Top-k 采样 · 只让前 k 名进入抽样箱
Top-k Sampling · Let Only the Top k Enter the Draw
sort probabilities → keep k → renormalize → sample
Top-k 采样只保留概率最高的 k 个候选,再把它们重新归一化后采样。k 限制的是候选数量,不是累计概率。
Top-k Sampling keeps only the k highest-probability candidates, renormalizes them, and samples. k caps candidate count, not cumulative probability.
01 · 从排行榜划一条人数线
01 · Drawing a headcount line on a leaderboard
只准前三名参加抽签时,被淘汰者为什么变灰,而前三名的抽签份额还会重新变大?
If only the top three may enter a draw, why do the rest turn gray while the survivors' shares grow?
k=3✂
02
拖 k,观察裁剪与重归一化
Move k and Watch Pruning Plus Renormalization
沿用概率柱语法
Probability-bar grammar
状态 A
Metric A
—
—
状态 B
Metric B
—
—
状态 C
Metric C
—
—
概率与输出均为固定种子的教学模拟,不代表真实模型。拖回主变量即可复核结论。
Probabilities and outputs are fixed-seed teaching simulations, not real model output. Move the main variable back to verify the conclusion.
03
把变化拆成 4 个零件
Break the Change into Four Parts
Top-k Sampling
PART 01
排序
Ranking
先按原概率从高到低排列,k 不改变原始名次。
Candidates are sorted by original probability; k does not change that ranking.
PART 02
裁剪
Pruning
第 k 名之后的候选变灰,采样概率归零。
Candidates below rank k turn gray and receive zero sampling probability.
PART 03
重归一化
Renormalization
保留候选按原相对比例放大,使总和重新等于 1。
Retained candidates scale in the same relative proportions until their sum returns to one.
PART 04
抽样词库
Sampling pool
抽样只会落在保留的 k 个 token 中。
The draw can land only on the retained k tokens.
04
最小机制:裁掉尾部,再除以保留质量
Minimal Mechanism: Drop the Tail, Then Divide by Retained Mass
Top-k Sampling
p′i = pi / Σj≤kpj
若 i 排名超过 k,则 p′ᵢ = 0;其余柱总和必须重新回到 1。
If i ranks below k, p′ᵢ = 0. The remaining bars must sum back to one.
拖动 k
Move k
候选数上限改变
candidate cap changes
尾部灰化
Gray the tail
被裁概率归零
pruned probability becomes zero
重归一化
Renormalize
保留柱总和回到 1
retained bars return to one
05
边界实验:把 k 裁到 1
Boundary Test: Cut k Down to One
主动制造失败
Create a failure
采样退化成单一路径
Sampling collapses to one path
设置 k = 1。唯一保留候选重归一化为 100%,抽样不再有分叉,效果等同于从头部确定选择。
Set k = 1. The only survivor renormalizes to 100%, leaving no sampling fork and behaving like a deterministic top choice.
尚未执行。先在主交互中观察正常机制。
Not run yet. Observe the normal mechanism in the main interaction first.
✗
Top-k 保留累计概率 k%。
Top-k keeps k percent cumulative mass.
→ ✓
k 是候选个数,不是概率阈值。
k is a candidate count, not a probability threshold.
✗
裁剪后概率总和可以小于 1。
Probabilities may sum below one after pruning.
→ ✓
采样前必须把保留候选重新归一化。
Retained candidates must be renormalized before sampling.
✗
k 越小,答案质量一定越高。
Smaller k always improves quality.
→ ✓
过小会消灭合理分叉并退化为僵硬选择。
Too small a k removes valid forks and becomes rigid.
06 · 一句话带走
06 · One line to keep
Top-k 固定保留前 k 个候选;拖动 k 能检验尾部灰化、保留柱重归一化和抽样词库同步收缩。
Top-k keeps a fixed number of leading candidates. Move k to verify tail graying, renormalized survivor bars, and a shrinking sampling pool.