@CamilleRoux: 对LLMs内部工作原理的精彩解释:tokens、embeddings、positional encoding、attention、feed-forward…
摘要
这条推文分享了一篇关于LLMs内部工作原理的详尽解释,涵盖了tokens、embeddings、positional encoding、attention和feed-forward网络,来源于0xkato的一篇博文。
查看缓存全文
缓存时间: 2026/06/15 02:50
大型语言模型(LLMs)实际上是如何工作的
来源:https://www.0xkato.xyz/how-llms-actually-work/
- 首页 (https://www.0xkato.xyz/)
- 博客 (https://www.0xkato.xyz/blog)
- 研究 (https://www.0xkato.xyz/projects)
- 关于 (https://www.0xkato.xyz/about)
- 作品集 (https://github.com/0xkato/Portfolio/tree/main)
2026年6月1日(星期一)· 阅读时长约26分钟
这篇文章将带你了解大型语言模型(LLM)的工作原理。现代LLM大多是通过反复堆叠Transformer模块构建而成,因此理解了Transformer的机制,你就能掌握大部分内容。
我将介绍现代基于Transformer的LLM内部的核心机制,跳过那些拗口的数学细节。别误会,你应该学习数学,但本文可以作为入门介绍。
大多数现代LLM共享相同的Transformer家族骨架。区别在于每个模型的训练数据、规模和配置选择,以及在此基础上进行的后训练。读完本文后,你应该能够阅读许多现代LLM的论文或模型卡片,并知道每一部分在架构中对应哪个环节。
以下是路线图:
- Token(令牌):一段文本如何变成一串整数
- Embeddings(嵌入):这些整数如何获得含义
- Positional Encoding(位置编码):模型如何知道令牌的顺序
- Attention(注意力):令牌之间如何共享信息
- Multi-head Attention(多头注意力):模型如何同时追踪多种关系
- Feed-Forward Network(前馈网络):模型存储的大部分结构知识所在
- Residual Stream & Layer Normalization(残差流与层归一化):使深层堆叠可训练的关键
- Predicting the Next Token(预测下一个令牌):模型实际输出什么,以及生成循环如何工作
- Architecture vs. Trained Weights(架构 vs. 训练权重):现代LLM之间的广泛共享与差异
从分词到下一个令牌预测的Transformer流水线
文中会穿插一些通俗解释,方便任何背景的读者理解。
分词
模型无法直接阅读文本。它们读取的是整数ID。这一步将你的提示词转换成这些整数序列。
这个转换步骤称为分词。分词器接收一个字符串,并生成一个整数序列,其中每个整数指向一个固定词表中的条目。现代LLM的词表通常包含数万到数十万个条目。
通俗解释:Token ID Token ID是模型用来表示词表条目的整数。模型处理的是这个数字,而不是文字本身。
Token通常不是完整的单词。它们通常是**子词(subword)**片段。例如单词“tokenization“可能被拆分成[“token”, “ization”]。单词“running“可能被拆分成[“run”, “ning”]。这样做的原因是效率。整词词表太大,且无法泛化到新词;字符级词表太小,迫使模型从零学习最简单的模式。子词分词介于两者之间:最常见的片段成为单个token,罕见或新颖的单词由更小的片段组合而成。
通俗解释:词表 词表是分词器固定的片段列表。每个片段都有一个ID,模型只能直接接收这个列表中的ID。
这种取舍会在一些意想不到的地方体现出来。经典例子:问LLM“strawberry“中有几个“R“。LLM过去常常答错。这不是模型计数能力失败,而是模型并不直接操作字母,它只操作那些恰好拼成一个人类会逐字母拆分的单词的token ID。
分词将文本转换为token ID
不同模型家族使用不同的分词器。GPT模型使用Byte Pair Encoding变体。LLaMA风格模型常用SentencePiece。这个选择会影响计算量(token越少,所需计算越少),以及多语言覆盖等因素,但基本结构相同:文本输入,整数输出。
现在,提示词已经变成了一个整数序列,下一步是赋予这些整数含义。
Embeddings(嵌入)
一个token ID(比如1024)仅仅是一个行索引。它本身没有任何含义。赋予它含义的是一个巨大的表格,叫做嵌入矩阵(Embedding Matrix)。
每个模型都有一个这样的矩阵。它有词表中每个条目对应的一行,每行是一个很长的数字向量。每行的长度就是模型的隐藏维度(hidden size)。在许多7B级别的模型中,每个token对应4096个数字。更大的模型通常使用更宽的向量。
通俗解释:向量 向量是一个数字列表。在Transformer中,每个token都会变成一个向量,这样模型就可以对它进行数学运算。
当分词器将一个整数交给模型时,模型会查找那一行,并使用该向量代替那个整数。这个向量就是该token的嵌入。它是模型对该token“含义”的表示,是在训练过程中学习得到的。
通俗解释:嵌入矩阵 嵌入矩阵是一个查找表。输入Token ID,输出学习到的向量。
这些嵌入的一个有趣特性是,语义相似的token最终会得到相似的向量。“king“的向量在空间上靠近“queen“的向量,“Paris“的向量靠近“France“的向量。这些都不是硬编码的,而是从大量文本训练中自然涌现的。模型之所以学习这些位置关系,是因为这样做能帮助它更好地预测文本。
你可以在嵌入上进行算术运算,有时还挺管用。著名的例子是king − man + woman ≈ queen。嵌入空间的几何结构承载着真实的语义关系,即使没有人告诉模型要这样构建。
嵌入空间的语义关系类比
需要明确的是:此时每个token都已替换为其嵌入,但嵌入本身并没有说明该token在序列中的位置。无论“dog“是你的提示词中的第一个词还是第五个词,它的向量都是一样的。这是个问题。
这正是位置编码需要填补的空白。
Positional Encoding(位置编码)
单纯的**自注意力(self-attention)**没有内置的词序表示。如果没有某种位置信号,它无法直接知道“dog”是出现在“bites”之前还是之后。
词序改变含义。因此模型需要另一个部分。它需要一种方法将每个token的位置信息注入到数学计算中。
通俗解释:位置编码 位置编码是模型获取顺序信息的方式。它告诉模型每个token在序列中的位置。
最初的Transformer论文(Vaswani et al. 2017)通过为每个位置分配一个独特的数字模式,并在所有其他处理开始之前将其直接加到每个token的嵌入上来实现。位置1有一种模式,位置5有另一种模式,位置100又是一种。这些模式来自不同频率的正弦和余弦波。这样一来,位置1的“dog“的嵌入就与位置5的“dog“的嵌入不同了,仅仅是因为加在它们上面的位置模式不同。
这个方法可行,选择正弦编码部分原因在于它可以外推到训练期间未见过的序列长度。但是,随着模型规模增大,加法位置方案仍然存在两个重要问题。
首先,嵌入必须同时携带含义和位置信息,共享同一组数字。它能打包的信息是有限的。
其次,特别是学习到的绝对位置嵌入无法很好地泛化。如果你只训练过长度不超过2048个token的提示词,模型在训练期间从未见过位置5000,那么这个位置的嵌入就不会以同样的方式被学习到。
现代模型大多使用一种不同的方案,称为旋转位置嵌入(Rotary Position Embeddings, RoPE),由Su等人在2021年提出,现在被LLaMA、Mistral、Gemma、Qwen以及大多数其他开源权重家族所采用。其直觉是:RoPE不是将位置信息加到每个token的向量上,而是根据token的位置,用一个依赖于位置的角度来旋转Query和Key向量。位置1的token旋转一小角度,位置100的token旋转更大角度。之后在注意力计算中比较两个token时,起作用的是它们的Query和Key旋转之间的差异,这个差异编码了它们之间的距离。
通俗解释:RoPE RoPE代表旋转位置嵌入。它不是添加一个位置向量,而是旋转Query和Key向量,使得相对距离在注意力计算中显现出来。
旋转位置嵌入按位置旋转向量
实际优势很明显。RoPE自然地编码了相对位置(这更接近注意力实际需要的)。它更容易泛化到更长的上下文。并且它不会给模型增加新的参数。
即使有了很好的位置编码,现代LLM也存在一个被记录在案的“中间迷失”问题(Liu et al. 2023)。它们使用长提示词开头和结尾的信息比使用中间的信息更可靠。这就是为什么像“把重要上下文放在前面”或“在结尾重复关键信息”这样的提示词工程技巧确实有效。模型并没有平等地使用提示词的每一部分。
有了token的含义和位置信息,下一个问题是:token之间究竟如何交换信息?
Attention(注意力)
这就是赋予该架构名称的机制——注意力。
在每个Transformer层内部,注意力做一件事:它让每个token可以查看它被允许看到的其他token,并决定哪些token对于预测下一个内容更重要。
它通过赋予每个token三种角色来实现这一点。每个token被转换成三个新的向量,称为Query、Key和Value(Q、K、V)。
通俗解释:Q、K、V Query的意思是“我在寻找什么”,Key的意思是“我能匹配什么”,Value是当匹配强烈时被复制的信息。
- Query 询问:“我在其他token中寻找什么?”
- Key 声明:“这就是我提供给看向我的token的信息。”
- Value 携带:“这就是匹配发生时被传递的信息。”
同一个token同时扮演这三个角色。Q、K、V的变换是通过学习到的矩阵完成的,因此模型在训练过程中会自行决定每个token应该寻找什么以及应该提供什么。
匹配通过一个相似度分数(similarity score) 进行。每个token的Query与它被允许看到的每个token的Key进行比较,使用缩放点积(scaled dot product)。直观地说,这衡量了两个向量对齐的程度。缩放是为了在应用softmax之前保持数值稳定。
通俗解释:点积 点积是一种简单衡量两个向量对齐程度的方法。对齐程度越高,匹配越强。
然后,匹配分数通过softmax转换成权重。Softmax接收一组任意数字,并将它们转换成总和为1的、类似概率的分布。匹配分数更高的token获得更高的权重,然后这些权重用于对Value向量进行加权平均。
通俗解释:softmax Softmax将原始分数转换成加起来为1的权重。高分得大权重,低分得小权重。
举个例子。考虑句子“The cat that I saw yesterday was sleeping.” 当模型处理“was”时,它需要弄清楚正在睡觉的主体是什么。“was”的Query向量与它被允许看到的token的Key向量进行比较。与“cat”的点积很高,因为模型已经学会像“was”这样的动词需要一个主语,而像“cat”这样的主语产生的Key向量能够很好地匹配。与“yesterday”的点积很低。Softmax将这些分数转换成权重,“cat”获得高权重,“yesterday”获得低权重。然后模型对相应的Value向量进行加权求和,因此“cat”的Value在结果中占主导地位。“was”的新表示现在主要由“cat”的Value塑造。这就是相隔几个位置的token如何成为指代对象。
GPT风格的语言模型有一个特定的约束:它们从左到右生成文本。位置5的token只能关注位置1到5。它不能关注位置6、7、8,因为这些还没有生成。这被称为因果掩码(Causal Masking)。实现很简单:未来token的匹配分数被设得极低,以至于经过softmax后它们的权重实际上为零。
通俗解释:因果掩码 因果掩码隐藏了未来token。它能防止仅解码器语言模型在预测下一个token时偷看后面。
显示因果掩码和对“cat”高注意力的注意力热力图
可解释性研究中最有趣的发现之一是关于专门的注意力头,称为归纳头(Induction Heads),由Anthropic在2022年发现。这些头学会了识别提示词中“A B … A”这种模式,并预测接下来会出现B。当模型第二次看到“A”时,归纳头会回溯到之前“A”出现的位置,查看它后面跟着什么,然后复制那个内容。它们是上下文学习(In-context Learning)背后最清晰的已知机制之一,即LLM从你的提示词中汲取模式并继续执行的能力。
通俗解释:归纳头 归纳头是一种注意力头,它注意到提示词中重复出现的模式,并帮助继续执行这些模式。
注意力有一个巨大的代价。在全注意力中,每个token要与它被允许看到的所有token进行比较,因此将提示词长度加倍大致会使计算量变为四倍。这就是为什么长提示词运行成本高,也是为什么大量近期研究致力于提高注意力效率(FlashAttention、稀疏注意力、线性注意力)。
但是,一个注意力头只给模型提供了一种关于这些关系的学习视角。
多头注意力
单次注意力传递只给模型提供了一种方式来决定哪些token对哪些其他token重要。这还不够。语言中同时存在许多种关系:主语和谓语动词的一致、代词和它们所指代的名字、跨句子的长距离引用、词序和局部词组。
多头注意力(Multi-head Attention)通过并行运行多次注意力来解决这个问题,每次并行传递在自己的较小空间内操作。每次并行传递称为一个头。
通俗解释:注意力头 一个注意力头是一个独立的注意力传递过程,拥有自己的学习到的投影。
这里有一个经常被描述错误的部分(包括许多教程)。每个头并不是得到原始token向量的一个文字切片。每个头拥有自己的学习到的投影矩阵,将完整的token向量映射到它自己较小的Q、K、V向量。因此,如果一个模型每个token有4096个数字,并且有32个头,那么每个头通常工作在128维的空间中,但这128个数字是完整4096维向量的学习到的投影,而不是一个固定的切片。它们是同一个token的不同“视图”,而不是不同的块。
每个头独立运行其注意力过程。然后所有头的输出被拼接起来,并通过一个最终的线性层,将它们混合回一个全尺寸的向量。模型也会学习这个最终的混合。
多头注意力结合了专门的注意力头
有趣之处在于,不同的头通常最终会部分地专门化。模型从未被告知每个头应该做什么,专门化是在训练过程中自然涌现的。研究人员发现了以下类型的头:追踪语法(将动词与其宾语、冠词与其名词联系起来)、找出哪个代词指代哪个名字、追踪位置模式、归纳头,以及更多。单个Transformer层可能有32个头。一个现代前沿模型有几十层。因此,一个典型的LLM有数千个注意力头,它们共同工作以实现所有不同的关系。
但是,即使有了所有这些,仅靠注意力还不够。模型还需要一个地方来存储它学习到的大量事实性知识和模式(例如“Paris是法国的首都”、“动词在疑问句中的词序”)。这个任务落到了前馈网络上(下一章将详细介绍)。
即使有了完美的注意力,如果没有足够多的参数,模型也无法存储所有具有足够保真度的知识。前馈网络(FFN)层通常贡献了模型参数的大部分。在一个典型的Transformer层中,参数量大致分布在注意力部分和前馈部分之间,但FFN通常占据较大的份额。它们是模型存储“知识”和“能力”的绝大部分所在。
最后一点:你经常会看到术语MLP与FFN交替使用。在Transformer论文中,每个块包含一个“位置前馈网络”,它本质上是一个小型的MLP。从功能上讲,它们的作用是相同的:一个两层FNN,带有非线性激活函数。但要注意:在一些论文或代码库中,当人们提到“MLP层”时,他们指的是Transformer块的这个部分,而不是整个块。
通俗解释:前馈网络 前馈网络是一个小型的神经网络块,独立地处理每个token的向量。它将向量转换到一个更大的空间(通常是隐藏维度的4倍),然后映射回来,同时应用非线性变换。
FFN的输入是经过注意力处理并添加了原始残差的token向量。在论文中,这个功能通常按如下公式描述: FFN(x) = activation(x·W₁ + b₁) · W₂ + b₂
逐步分解:
Attention produces a new representation for each token that has gathered information from other tokens. But that’s still local — it only moves information around. The FFN is where the model gets to apply its stored knowledge to that information. It’s a transformation that happens independently for each token, using learned patterns that are shared across all positions. This is often described as a key-value memory store. Each input token’s vector activates some of these stored patterns and suppresses others, producing an output vector that incorporates relevant knowledge.
Now let’s walk through the math. The input vector is projected up to a much wider intermediate space using matrix W₁. A typical 7B-parameter model with 4,096-dimension hidden size will project to 11,008 or so. This creates room for many overlapping patterns to be represented at once. The activation function then introduces a nonlinearity. Modern models mostly use SwiGLU or GELU. LLaMA 2/3 use SwiGLU. Without nonlinearity, stacking multiple FFN layers would collapse into a single linear transformation.
Once activated, the intermediate vector is projected back down to the original hidden size using matrix W₂. The output is a new vector of the same size as the input, but containing information the model has retrieved from its stored knowledge.
The practical effect is that different FFN neurons specialize to handle different kinds of patterns. Researchers have found FFN neurons that activate strongly for code versus natural language, for sentiment analysis versus factual recall, for math problems versus general reasoning. These specializations aren’t programmed — they emerge because they help the model minimize next-token prediction loss, and that’s a remarkably effective training signal for carving up the space of language.
FFN layer projection and activation
Some architectures, like the Mixture of Experts (MoE), replace the single large FFN with multiple smaller specialized FFNs called experts. A learned routing mechanism picks which experts to use for each token. This gives more total parameters without the corresponding increase in compute, because each token only activates a subset of experts. Mixtral, Grok, and DeepSeek-V2/MoE use this approach.
One of the most remarkable things about feed-forward networks is neuron interpretability — a very active research area. While the individual neurons inside an FFN do not correspond cleanly to human concepts, recent work shows that features (i.e., concepts or ideas the model uses) are often represented as directions in the activation space, not as single neurons. Sparse autoencoders (SAEs) try to decompose activation vectors into sparse sets of interpretable features. Anthropic’s work on toy models of superposition suggests models learn many more features than they have dimensions to represent them clearly, which they manage by packing multiple features into the same dimensions in a way that’s sparse — i.e., any given input activates only a small fraction of the possible features. This also makes FFNs the primary bottleneck for interpretability.
Every attention operation and every FFN step would be impossible to train in a deep stack without two critical pieces: the residual stream and layer normalization.
The Residual Stream & Layer Normalization
Two mechanisms run in the background of every layer, invisible but essential. The residual stream preserves information across layers, and layer normalization stabilizes signals.
The Residual Stream (Skip Connections)
The original Transformer paper introduced residual connections, now universally used. The idea is simple: the input to a sublayer (attention or FFN) is added back to its output. Mathematically: output = sublayer(input) + input.
Tiny explainer: residual connection A residual connection adds the input of a layer to its output. It helps gradients flow smoothly and preserves information.
Why does this matter? In a deep stack of layers, information can degrade as it passes through many transformations. The residual stream acts as a highway. Academic metaphor: the residual stream is like a student taking notes (adding new info) while still keeping the original lecture transcript (preserving prior information). This is crucial for training deep networks; without it, gradients vanish.
Layer Normalization
Transformers also use layer normalization, which normalizes the activations across the hidden dimension for each token independently. It ensures that the scale of vectors stays consistent.
Tiny explainer: layer normalization Layer normalization re-centers and re-scales the activations to keep them in a stable range across all layers.
The two components work together. The residual stream passes a mostly intact signal forward, and layer normalization ensures that each sublayer receives a well-behaved input.
Layer normalization and residual connection in a transformer block
Different model families arrange them slightly differently. GPT models used “post-norm” (norm after residual addition). LLaMA uses “pre-norm” (norm before each sublayer). Pre-norm tends to be more stable during training.
The residual stream also carries a hidden dimension that acts like the “main channel” of information. The input token embedding goes in at the bottom, and the final prediction comes out the top. Every layer’s attention and FFN write their outputs into this stream.
Now that we understand what happens inside a single layer, we can look at what comes out at the end.
Predicting the Next Token
After all the transformer layers, we have a sequence of vectors, one per input token position. Each vector has been processed through dozens of layers of attention and FFN, carrying information aggregated from the positions that matter for that token, filtered through stored knowledge.
The final step: turn these vectors into a probability distribution over the vocabulary. This is done by an unembedding layer, usually a linear transformation that projects the final hidden states into scores for each token in the vocabulary.
Tiny explainer: logits Logits are the raw scores before softmax — each token in the vocabulary gets a score.
The output is a vector of logits, with one entry per token in the tokenizer’s vocabulary. A softmax converts these logits to probabilities that sum to 1. The model then uses these probabilities to decide what to output, through a decoding strategy (greedy, sampling with temperature, top-k, top-p, etc.).
Tiny explainer: decoding strategy The way the model picks the next token from the probability distribution. Options include greedy (always pick the highest probability token), or sampling with temperature (higher temperature = more randomness).
The generation loop is autoregressive — the model feeds its output back in as input for the next step. The sequence of tokens grows by one at each step. The model also stores Key-Value caches from earlier positions to avoid recomputing them. This is a critical optimization for fast generation, trading memory for computation.
The prompt goes through tokenization, passes through the transformer pipeline, and the last token’s position gives the prediction for the next token.
By default, the loss function during pre-training is next-token prediction loss (cross-entropy loss). The model gets a prompt, predicts the next token, compares its prediction to the actual token, and updates weights to minimize the loss. The model never sees the full sequence at once — it predicts one token at a time, always looking at the tokens before it (causal masking).
Architecture vs. Trained Weights
Two concepts that get blurry in conversation but should be kept distinct: architecture and trained weights. Understanding the difference helps when reading about new models.
What’s Architecture
Architecture refers to the design choices that are fixed before training starts:
- The number of layers
- The hidden dimension size
- The number of attention heads
- The activation function
- The tokenizer and vocabulary size
- The type of positional encoding
- The normalization scheme
These are specified in model configs. For example, LLaMA 2 13B uses:
- 40 layers
- 5,120 hidden size
- 40 heads
- SwiGLU activation
- 32,000 vocabulary
- RoPE with 4,096 context length
Architecture determines the model’s capacity — how many parameters it can have, how much computation each forward pass requires, and what patterns it’s able to express.
What’s Trained
Trained weights are the actual numerical values in every parameter that result from the training process. The embedding matrix, Q/K/V projections, FFN weight matrices, layer norm parameters — every learned transformation. All of these start as random numbers and get shaped by training data.
Researchers have found that training often ends up in similar local minima — different training runs with the same architecture can produce models with different exact weights but similar behavior patterns. This suggests that the architecture constrains what’s possible, but the data determines the specific weights.
What This Means
Understanding the difference helps when reading about new models:
- When a paper says “we scaled to 70B parameters,” that’s an architecture/scale choice that determines compute cost and capacity.
- When a paper says “we trained on 2 trillion tokens,” that’s about data — it says nothing about the architecture.
- When a paper says “we used SFT and RLHF,” that’s post-training — fine-tuning the weights without changing the architecture.
The pre-training loss function is almost always next-token prediction. After pre-training, models undergo various post-training procedures (SFT, RLHF, DPO) that modify the weights but leave the architecture unchanged. These steps are what turn a raw pre-trained model into something that follows instructions well. This is often described as “aligning” the model.
Tiny explainer: SFT Supervised Fine-Tuning — training on human-written demonstrations of desired behavior. Tiny explainer: RLHF Reinforcement Learning from Human Feedback — using human preferences to optimize the model’s outputs via reinforcement learning. Tiny explainer: DPO Direct Preference Optimization — an alternative to RLHF that directly optimizes from preference data without a separate reward model.
Modern LLMs also support tool use and retrieval-augmented generation (RAG). These abilities are either learned during fine-tuning or “emerge” from the pre-trained capabilities of the model, often with a combination of both. They are not part of the core architecture.
Summary
Here’s what we covered:
- Tokenization: Text → integer IDs using subword splits.
- Embeddings: Integer IDs → learned vectors with semantic meaning.
- Positional Encoding: Injecting position information via RoPE for relative distances.
- Attention: Tokens exchanging information through Q/K/V, weighted by similarity.
- Multi-head Attention: Parallel attention heads with different learned projections for different relationships.
- Feed-Forward Network: Storing and applying knowledge independently per token.
- Residual Stream & Layer Normalization: Preserving information and stabilizing training.
- Predicting the Next Token: Unembedding to logits, decoding strategies, and autoregressive generation.
- Architecture vs. Trained Weights: Fixed design choices vs. learned parameters, plus post-training steps like SFT, RLHF, DPO.
If someone asks you “How does an LLM work?” you can now give them a clear, structured answer — and point them to this post for the details.
The most surprising thing about transformers, in my view, is that such a conceptually simple stack of mechanisms — look up embeddings, add positions, mix tokens with attention, and process each token through a learned MLP — produces the sophisticated behavior we see in modern LLMs. Everything that makes LLMs impressive emerges from scaling this basic pattern to enormous size and training on vast datasets.
This basic pattern is also the foundation that everything else in modern NLP builds on — from translation and summarization to code generation and reasoning. Understanding it gives you the vocabulary to talk about any of those capabilities.
This post is part of my ongoing series on AI fundamentals. If you found it useful, consider subscribing to updates. Feedback and corrections welcome.
相似文章
大型语言模型是如何工作的(26分钟阅读)
详细讲解基于Transformer的大型语言模型的工作原理,涵盖分词、嵌入、注意力机制和下一个词元预测,无需复杂数学。
@Tabbu_ai: https://x.com/Tabbu_ai/status/2058145123444347339
一篇教育性推文串,解释了理解和从头构建LLM架构的11个关键课程,涵盖token、嵌入、注意力、位置编码、数据质量和常见误解。
大语言模型实际工作原理
深入剖析现代大语言模型的工作原理,涵盖从分词到下一个词预测的核心机制,无需复杂数学知识。
@Potatoloogs: LLM 内部究竟怎么运作:从 token 到 next-token,九个核心机制完整梳理 a)Tokenization:模型读的不是文字,是整数 · 文本先被切成 subword 片段,再映射成整数 ID;现代 LLM 词表通常有数万到数…
本文从 tokenization 到 next-token 预测,系统梳理了现代 LLM 内部的九个核心机制,包括 tokenization、embedding、位置编码、注意力、多头注意力、前馈网络等,并比较了不同模型的架构差异。
@techNmak: 这是学习LLM工作原理的最佳方式。交互式3D,逐步讲解。涵盖:→ 嵌入 → 层归一化 → 自注意力…
一个交互式3D逐步指南,通过可视化方式学习LLM工作原理,涵盖嵌入、自注意力、softmax等关键Transformer概念。推荐使用视觉化方法,而非阅读论文。