S3-17 · 进阶 · 自回归生成入口S3-17 · Advanced · Gateway to autoregressive generation

解码器 · 写出一个,再把它变成已知Decoder · Write One Token, Then Make It Part of the Known Past

known prefix → predict next token → append → repeat

解码器(Decoder)在已知输入和先前输出条件下逐步预测后续 token。每一步只使用当前已知前缀,新 token 加入后才成为下一步可见的过去。A decoder predicts later tokens step by step, conditioned on known input and previous outputs. Each step uses only the known prefix; a new token becomes visible past only after it is appended.

01 · 一格一格续写01 · Continue one cell at a time

写句子时,下一词尚未出现。decoder 怎样一边不能看未来,一边把句子越写越长?The next word does not exist yet. How does a decoder grow a sentence while staying unable to see the future?

02 按“下一步”,让已知前缀增长一格Press “Next Step” to Grow the Known Prefix by One

一步 = 一个 tokenone step = one token
当前长度Current length
2
token
当前步骤Current step
0
已生成 tokengenerated tokens
未来可见Future visible
0
因果遮罩生效causal mask active

候选概率是固定种子的教学模拟值。页面只演示架构级循环,不代表真实模型会生成这些词或概率。Candidate probabilities are fixed-seed teaching values. This page demonstrates the architecture-level loop, not what a real model would generate or score.

03 decoder 单步的 4 个零件Four Parts of One Decoder Step

prefix · mask · score · append
PART 01

已知前缀Known prefix

输入提示与已经生成的 token 排成当前序列。Prompt tokens and previous outputs form the current sequence.

PART 02

因果注意力Causal attention

每个位置只能汇总自己与左侧已知内容。Each position gathers only itself and known content to the left.

PART 03

候选 logitsCandidate logits

最后位置输出词表候选的分数。The final position outputs scores for vocabulary candidates.

PART 04

追加与回送Append and feed back

选中的 token 追加后成为下一步的已知输入。The selected token is appended and becomes known input next step.

04 最小机制:把上一步输出接回下一步输入Minimal Mechanism: Feed the Previous Output into the Next Input

p(tn+1 | t≤n)
logitsn+1 = Decoder(t1…tn)
tn+1 = Select(logitsn+1)
按下一步时,条件从 t≤n 增长为 t≤n+1。未来从未预先存在于可见序列中。On the next step, the condition grows from t≤n to t≤n+1. Future tokens never pre-exist in the visible sequence.
读取前缀Read prefix只含已知 tokenknown tokens only
预测一个Predict one输出下一位置分数score the next position
追加再循环Append and repeat新 token 变成过去new token becomes past

05 边界实验:预先塞入未来答案Boundary Test: Preload the Future Answer

主动制造失败Create a failure

这不再是逐步预测,而是答案泄漏This stops being stepwise prediction and becomes leakage

把尚未生成的“世界”预先放进序列,并允许当前位置连过去。看似一次命中,其实违反因果边界。Place the not-yet-generated token “world” into the sequence and let the current position attend to it. The apparent hit violates the causal boundary.

尚未执行。画布只显示当前已知前缀。Not run yet. The canvas shows only the known prefix.
decoder 一次就把整句同时写完。A decoder writes the whole sentence at once. → ✓ 自回归生成一次只追加一个 token。Autoregressive generation appends one token per step.
新 token 出现前就能被注意力读取。Attention can read a token before it exists. → ✓ 它追加后才进入下一步已知前缀。It enters the known prefix only after being appended.
decoder 就是某一种选词算法。A decoder is one particular selection algorithm. → ✓ 架构产出 logits,贪心、采样等规则再选择。The architecture produces logits; greedy or sampling rules select afterward.
06 · 一句话带走06 · One line to keep

decoder 只用已知前缀预测下一枚 token,追加后再重复;连续按“下一步”,就能看见因果遮罩怎样随序列一格格增长。A decoder uses only the known prefix to predict one next token, appends it, and repeats. Step forward to watch the causal mask grow one cell at a time.