skip to content

Why is beam search rarely used for open-ended LLM text generation?

level: middleimportance: nice to knowfreq 30%

answer

  1. optimises the sequence, not the token
  2. most likely long text is boring
  3. width multiplies compute and cached state
  4. fine for translation, wrong for stories
  5. search moved up to whole responses

basics

~20 s

Beam search maximises total sequence likelihood, and the most likely long text is generic and repetitive. It also costs several forward passes per step, fits streaming and large-batch serving badly, and its guarantee only pays off on short outputs with one right answer, like translation.

solid answer

~50 s

Beam search keeps the b most promising partial sequences alive at each step and expands all of them, aiming to find a high-likelihood *sequence* rather than a locally good token. That objective is a good fit for tasks with essentially one correct output and short spans — machine translation, speech transcription — where you want the best rendering and diversity is not the goal. It is a bad fit for open-ended generation, because maximising likelihood there converges on bland, repetitive, high-frequency text; that finding is what motivated nucleus sampling in the first place. The practical costs compound the mismatch: b beams multiply per-step compute and cached state, streaming is awkward because an early token can still be pruned, and it does not compose with tool-calling loops. Modern quality-by-search has moved up a level — you sample several complete answers and select among them — rather than searching the token lattice.

go deeper

for a junior

Know that beam search keeps several candidate continuations alive and picks the best complete sequence, and that it comes from translation-style tasks rather than open-ended chat generation.

for a middle

Explain the objective mismatch: it maximises sequence likelihood, and the most likely long text is generic and loop-prone. Note that greedy decoding is just beam search with width one.

for a senior

Add the serving reality — width multiplies compute and cached state, streaming cannot safely emit a prunable prefix, and tool-call boundaries break the notion of scoring one whole sequence.

for a principal

Frame it as where search belongs in the stack: token-level search was displaced by truncated sampling below and response-level candidate selection above, and the tradeoff you actually own is how many full candidates a quality target justifies paying for.

## What beam search does Greedy decoding takes the highest-probability token at each step and never reconsiders. That is locally optimal and globally short-sighted: a slightly worse token now can open a much better continuation later. Beam search is the standard remedy. It keeps b partial hypotheses ("beams"). At each step it expands every beam with its top candidates, scores every resulting extension by the accumulated log-probability of the whole sequence, and keeps the best b. At the end you return the highest-scoring complete sequence. With b = 1 it degenerates to greedy decoding; larger b explores more of the space. Because raw log-probability sums penalise long sequences (every extra token adds a negative term), implementations normalise by length, usually with a tunable length-penalty exponent. That normalisation is itself a hint that the objective is a proxy rather than the thing you want. ## Where the objective fails The deep problem is not efficiency, it is the objective. Beam search seeks the highest-likelihood sequence, and for open-ended generation the highest-likelihood sequence is not the best text. Human writing is not maximally probable — it is full of locally surprising choices, and its per-token surprise fluctuates. The maximum-likelihood path, by contrast, is the safe, high-frequency, cliché-dense path, and it degenerates into loops: once a phrase is likely, repeating it stays likely, and the search happily walks that lattice. This observation — that likelihood maximisation produces degenerate text while sampling from the truncated distribution does not — is the argument that put nucleus sampling in every serving stack. So the tasks split cleanly. If there is essentially one right answer and the output is short — translating a sentence, transcribing audio, converting a query to a formal expression — searching for the best sequence is meaningful and beam search earns its keep. If the output is long, open-ended, or valued for variety, the objective is wrong before you consider the cost. ## Where the cost fails Even where the objective is defensible, modern serving makes beam search unattractive. It multiplies work per step. Maintaining b hypotheses means b times the per-step compute and b times the cached attention state, for one returned answer. On a shared inference cluster that is throughput you are spending on a single request. It fights streaming. You cannot safely emit a token to the user while a competing beam could still win, because the prefix you already showed might be pruned. Products where the user watches tokens arrive have no clean way to expose it. It fights the agent loop. Long generations, tool calls that inject external observations mid-sequence, and interleaved reasoning make "the whole sequence" a moving target; the search cannot score across a boundary where an external system contributes content. And it needs its own tuning — beam width and length penalty — which becomes another axis to maintain per task. ## What replaced it The idea that a bit of search improves output did not die; it moved up a level of granularity. Rather than searching over tokens, systems generate several complete candidate responses independently and then choose among them — by agreement, by a verifier, by a scoring model, or by running tests. That is cheaper to reason about, parallelises cleanly across requests, works with streaming (you stream only the winner, or the first one to validate), and composes with tool use. It is also honest about what it costs: n candidates is n times the tokens, visible on the bill. For interviews, the useful summary is historical: beam search is the decoder of the neural machine translation era, still correct for that class of task, and displaced for open-ended generation by truncated sampling below and response-level selection above.

  • If beam search finds higher-likelihood text, why does that text read worse?
    Because likelihood is a proxy for quality, not quality itself. Natural writing is not maximally probable — it carries local surprise, varied phrasing and specific detail, all of which lower its likelihood. Optimising the proxy hard drives output toward generic, high-frequency, repetitive language. It is a textbook case of a metric degrading once you optimise directly against it.
  • What is the relationship between beam width and greedy decoding?
    Greedy decoding is beam search with width 1: keep one hypothesis and always extend it with the argmax. Increasing the width explores more of the sequence space and raises the score of the returned sequence, but for open-ended text a higher-scoring sequence is often a *worse* one, which is why widening beams there tends to make output blander rather than better.

Beam search is like writing an essay by always choosing the least surprising next word while keeping a few drafts alive — you end up with something safe, fluent and utterly forgettable.

saying these in an interview costs you the question

  • Claims beam search gives more creative output
  • Thinks beam search removes hallucinations
  • Says greedy decoding is unrelated to beam search
  • Assumes higher likelihood always means better text
  • Ignores that beam width multiplies per-step cost

context