← Back to LLMs Mind Map
⚡ LLMsID: decoding-strategies

Decoding Strategies

解码策略
🎯Core Definition
Decoding strategies decide how to pick the next token from the vocabulary distribution during generation. Greedy takes the argmax; beam search keeps the top-BB paths; temperature rescales the logits (T→0T \to 0 recovers greedy, T>1T > 1 flattens the distribution for more randomness); top-k samples only among the kk highest-probability tokens; top-p (nucleus) samples from the smallest set whose cumulative probability exceeds pp. Standard order: temperature on the logits first, then top-p truncation, then sampling.
💡Use Cases
conversational and creative generation wants diversity and fluency — sampling (top-p + temperature + top-k); translation, summarization, code want deterministic output — greedy or a small beam; to suppress low-probability tokens while keeping randomness, top-p adaptively truncates by distribution shape.
⚡Key Problems Solved
greedy argmax tends to repeat and loop with little diversity; pure sampling picks low-probability tokens, producing ungrammatical or factually wrong output. top-p adapts the candidate set to the distribution shape (large when flat, small when peaked), temperature controls logit sharpness, and the pair balances quality vs diversity; beam's BB parallel paths mitigate greedy myopia.
🎯Core Interview Exam Points
Fundamentals · Production Scenarios · Deep Dive
Core Def
Explain the core definition, underlying mechanism/math, and key principles of Decoding Strategies.
Use Cases
In production engineering, what are the primary use cases for Decoding Strategies and what core pain points does it solve?
🔥 High-Frequency Deep-Dive Questions
1
Role of temperature; what do T=0 and T→∞ degenerate to?
2
top-p vs top-k? Why is top-p more adaptive?
3
Why temperature before top-p? What if the order is swapped?
4
Drawbacks of greedy and beam? Effects of beam size?
5
Sampling vs deterministic decoding: suitable tasks and the trade-off?
Updated 2026-08-12
🎯
Verify Mastery: Practice Exam Questions for "Decoding Strategies"
Take pitfall multiple-choice questions with derivation options; mistakes are automatically logged.
🚀 Start Card Practice ➔
← Previous CardPadding & PackingNext Card →Speculative Decoding (cross-module)

🔗 More LLMs Knowledge Cards

引用出处: TalentMe 450+ 工业级 AI 架构考点知识库 (Tech Vault) · 遵循 CC-BY-4.0 知识共享协议
URL: https://talentme.airsota.com/resources/tech/roadmap/mindmap/LLM/card/decoding-strategies
中文速览与面试要点

解码策略 (Decoding Strategies)

定义: 解码策略决定生成时如何从词表概率分布中选取下一个 token。greedy 取 argmax;beam search 保留前 B 条路径;temperature 先缩放 logits (T 0 退化为 greedy,T > 1 分布变平、更随机);top-k 只在概率最高的 k 个 token 中采样;top-p (nucleus) 在累计概率超过阈值 p 的最小候选集合中采样。标准组合顺序:先 temperature 缩放 logits,再 top-p 截断,最后采样。 使用场景: 对话、创作等需要多样性与自然度时用采样组合 (top-p + temperature + top-k);翻译、摘要、代码生成等期望确定性输出时用 greedy 或小 beam;需要抑制低概率 token 又保留随机性时,用 top-p 按分布形状自适应截断。 解决的问题: greedy 只取最大概率项,易陷入重复循环(“复读机”问题)且多样性差;纯随机采样会选中低概率 token,产生语法或事实错误。top-p 随分布形状自适应候选集(分布平坦时集合大、尖锐时集合小),temperature 控制 logits 锐利度,二者配合在质量与多样性之间取得平衡;beam 用 B 条并行路径缓解贪心解码的局部短视。

核心要点

  • temperature 的作用与极限:T=0、T 分别等价于什么解码?
  • top-p 与 top-k 的区别?为什么说 top-p 更自适应?
  • 为什么标准顺序是先 temperature 再 top-p?顺序颠倒会怎样?
  • greedy 与 beam search 的缺点?beam size 太大/太小的影响?
  • 采样与确定性解码分别适合什么任务?如何权衡?