Compare greedy decoding, top-k sampling, and top-p (nucleus) sampling.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Greedy takes the argmax token every step. Deterministic and cheap, fine for short factual answers and structured extraction. Failure mode: repetition loops ("the the the", or paragraph-level cycles) and blandness - locally optimal tokens don't compose into globally good text, and the model can enter self-reinforcing repetition where prior repeats make the next repeat more likely.
Full worked answer with diagram
Greedy takes the argmax token every step. Deterministic and cheap, fine for short factual answers and structured extraction. Failure mode: repetition loops ("the the the", or paragraph-level cycles) and blandness - locally optimal tokens don't compose into globally good text, and the model can enter self-reinforcing repetition where prior repeats make the next repeat more likely.
Top-k restricts sampling to the k highest-probability tokens (renormalized), typically k = 20-50. Problem: k is static while the distribution's shape varies enormously per step. When the model is confident (one token at 0.95), k = 40 admits 39 junk tokens; when it's genuinely uncertain across 200 plausible continuations (start of a story sentence), k = 40 truncates valid diversity.
Top-p / nucleus (from Holtzman et al., "The Curious Case of Neural Text Degeneration") adapts: keep the smallest set of tokens whose cumulative probability ≥ p (e.g. 0.9), renormalize, sample. Confident step → nucleus is 1-2 tokens; uncertain step → nucleus is large. This adaptivity is why top-p became the default. Its residual weakness: at high temperature the flattened distribution lets the nucleus swell to include genuinely bad tokens - which is what min-p (keep tokens with p ≥ min_p × p_max) addresses by anchoring the cutoff to the top token's confidence.
The key insight behind all truncation sampling: the model's probability mass is well-calibrated at the head of the distribution and unreliable at the tail - a long generation will eventually sample a tail token, and one bad token can derail everything after it (errors compound autoregressively). Truncation cuts the tail; temperature shapes what remains. In practice these compose: temperature + top-p (+ optionally top-k as a hard cap) is the standard stack, with greedy/T≈0 for anything with a right answer.
Worth sketching. It fixes the order of operations, which is what makes the top-p versus min-p difference concrete.
flowchart LR
Z["logits over vocab"] --> GD["greedy: argmax, skip the rest"]
Z --> T["temperature: z / T"]
T --> SM["softmax"]
SM --> K["top-k: fixed k,<br/>ignores distribution shape"]
SM --> P["top-p: smallest set with<br/>cumulative mass p, adapts per step"]
SM --> MP["min-p: keep p above min_p x p_max,<br/>anchored to the top token"]
K --> R["renormalise, then sample"]
P --> R
MP --> R
What a good answer covers
- Greedy takes the argmax token every step
- Deterministic and cheap, fine for short factual answers and structured extraction
- Failure mode: repetition loops ("the the the", or paragraph-level cycles) and blandness - locally…
- Top-k restricts sampling to the k highest-probability tokens (renormalized), typically k = 20-50
- Problem: k is static while the distribution's shape varies enormously per step
Key terms: Greedy · Top-k · Top-p / nucleus · min-p
In the glossary: Nucleus sampling (top-p) · Temperature
Interviewer follow-ups to expect
Why does greedy decoding loop, mechanistically?
When does top-p fail and how does min-p fix it?
Top-p / nucleus (from Holtzman et al., "The Curious Case of Neural Text Degeneration") adapts: keep the smallest set of tokens whose cumulative probability ≥ p (e.g. 0.9), renormalize, sample. Confident step → nucleus is 1-2 tokens; uncertain step → nucleus is large. This adaptivity is why top-p became the default. Its residual weakness: at high temperature the flattened distribution lets the nucleus swell to include genuinely bad tokens - which is what min-p (keep tokens with p ≥ min_p × p_max) addresses by anchoring the cutoff to the top token's confidence.
Why is sampled text at T=1 often worse than the model's "true" distribution would suggest?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep