What is the difference between greedy decoding and beam search for generating a sequence? Why is neither guaranteed to find the most probable sequence?
Sequence models and transformers, Decoding
Level L1 Beginner. Length Short. Nature Th Theoretical.
What's being asked
Whether you understand that both are approximate searches over an exponentially large space.
Key idea
Greedy keeps the single best token at each step. Beam search keeps the best partial sequences (by total log-probability) at each step. The search space has sequences, so both are approximate.
Steps
- The goal is to find , but there are candidate sequences for vocabulary and length .
- Greedy picks at every step. It is cheap, but an early choice that looks best may lead to a poor continuation.
- Beam search with beam width keeps partial sequences, extends each by every token, and keeps the best of the candidates.
- Beam search with is greedy. Larger costs about times more and usually finds higher-probability sequences.
- Neither is exact: a sequence whose prefix falls out of the beam can never come back.
Common mistakes
- Saying beam search is exact if is large. It is exact only when the beam is wide enough to hold every partial sequence, about of them.
- Forgetting that for open-ended text, the highest-probability sequence is often dull and repetitive.
How long your answer should be
4–5 sentences.
Last checked on 4 December 2026.
Read this
Previous in Sequence models and transformers: Why does a maximum-likelihood -gram language model fail on unseen -grams, and what does smoothing do about it?
Next in Sequence models and transformers: How do the training objectives of BERT (masked language modelling) and GPT (causal language modelling) differ, and what does each allow the model to attend to?