跳到内容

其他

Top-p / Nucleus sampling

Top-p / nucleus sampling

从累积概率达 p 的最小 token 集合中采样的方法,会随模型信心自动调整候选范围。

登入以收藏
Top-p sampling(又叫 nucleus sampling)把模型的选择限制在累积概率达到至少 p(通常 0.9 或 0.95)的最小 token 集合,然后从这个集合采样。模型有信心时,「nucleus」可能只有 2-3 个 token。模型不确定时,nucleus 扩大到 50+ token。 它重要的原因是:top-p 能根据 context 自适应,固定 k 的方法做不到。Top-k 50 永远考虑 50 个 token——即使模型已经强烈偏好某一个——会产生噪声。Top-p 只在模型自己不确定时才扩大考虑范围,输出更自然、更一致。 举个例子:续写「The capital of France is」——模型对「Paris」有 99%+ 概率。Top-p 0.9 选 Paris。续写「My favorite color is」——概率分散在 red、blue、green 等等。Top-p 0.9 会考虑所有常见颜色字。Top-k 50 两个情况都会包含 0.0001% 概率的冷门 token,浪费。 多数 API 让你同时设 temperature 跟 top-p。常见默认:temperature 0.7-1.0、top-p 0.9-0.95。要 deterministic 输出(code、JSON),用 temperature 0——top-p 就无关紧要了。延伸阅读:temperature、top-k、sampling、decoding。

最后更新: 2026-04-29

We use cookies

Anonymous analytics help us improve the site. You can opt out anytime. Learn more

Top-p / Nucleus sampling · BuilderWorld