S1-20 · 基础 · 分词族S1-20 · Foundation · Tokenization family
Token ID · 文字进入模型前的整数索引
Token ID · The Integer Index Before Text Enters the Model
token → vocabulary index → embedding row → dense vector
模型不会直接拿文字做矩阵运算。分词器先用词表把每个 token 换成整数 ID,再用 ID 找到对应的嵌入向量行。
Models do not multiply text directly. The tokenizer maps each token to a vocabulary ID, which looks up one embedding-vector row.
01 · 想象图书馆索书号01 · Think of a library call number
书名不能告诉书架机械臂去第几格;一个整数索引怎样把 token 送到正确向量行?
A title cannot tell a shelf robot which slot to open. How does an integer index route a token to the right vector row?
#841
02
点 Token,看它翻成 ID 再查表 Select a Token, Flip to Its ID, Then Look It Up
唯一变量:所选 token
One variable: selected token
Token
AI
字符串片段
string piece
Token ID
841
vocabulary v1
嵌入维度Embedding dim
4
row 841 → ℝ4
AI
→
#841
→
[0.00, 0.00, 0.00, 0.00]
03
一次查表的 4 个零件
Four Parts of One Lookup
piece · ID · row · vector
TOKEN
文字片段Text piece
分词器先产出词表允许的 token。
The tokenizer first emits a vocabulary-approved token.
INTEGER
Token ID
ID 是该 token 在当前词表中的整数位置。
The ID is the token's integer position in the current vocabulary.
LOOKUP
查行Row lookup
ID 直接索引嵌入表的一行,不需要理解文字。
The ID indexes one embedding row without interpreting text.
VECTOR
稠密向量Dense vector
取出的连续数值才进入后续矩阵计算。
The retrieved continuous values enter later matrix operations.
04
最小机制:ID 就是嵌入表行索引
Minimal Mechanism: The ID Is the Embedding-table Row Index
embedding = E[id]
id = V[token] e⃗ = E[id]
V 把 token 映射到整数,E 用这个整数选一行。上方每次换 token,ID、行号与四维向量都连锁刷新。
V maps the token to an integer, and E uses that integer to select a row. Changing the token above refreshes ID, row, and four-dimensional vector together.
点一个 token
Select a token确定词表项identify vocabulary entry
读取整数 IDRead integer ID定位 E 的一行
locate one row in E
取出 e⃗Retrieve e⃗文字变为可计算数值
text becomes computable values
05 边界实验:Token ID 不是跨词表通用身份证
Boundary Test: A Token ID Is Not a Universal Identity
主动制造失败Create a failure
切换到词表 v2,保留同一个 token
Switch to vocabulary v2 while keeping the same token
“AI”在 v1 是 841,在 v2 可以是 5120。把一个模型的 ID 直接送进另一个词表,会查到错误行。
“AI” may be 841 in v1 and 5120 in v2. Sending an ID from one model into another vocabulary can retrieve the wrong row.
尚未执行。先点四个 token 看 v1 查表。Not run yet. Inspect all four v1 lookups first.
✗ Token ID 本身包含词义。A Token ID itself contains meaning. → ✓ ID 只是当前词表的行索引。 An ID is only a row index in one vocabulary.
✗
同一个 ID 在所有模型中表示同一 token。 The same ID means the same token in every model.
→ ✓
ID 映射属于具体 tokenizer/词表版本。
ID mappings belong to a specific tokenizer and vocabulary version.
✗
模型直接读取 token 文本。
The model directly reads token text.
→ ✓ 计算入口是由 ID 查出的嵌入向量。
Computation begins with an embedding vector looked up by ID.
06 · 一句话带走06 · One line to keep
Token ID 是 token 在具体词表中的整数索引,用来查找对应嵌入向量行;点击任一 token 可验证文字、ID、行与向量如何连锁变化。
A Token ID is a token's integer index in a specific vocabulary, used to look up its embedding row. Select any token to verify the text-to-ID-to-row-to-vector chain.