Notes

Greedy Decoding

A text generator never produces a sentence in one piece. It produces a probability distribution over the next token, then another, and something has to turn those distributions into words. Greedy decoding is the simplest possible answer: at every step, take the single most probable token and move on.

What the decoder does
Each step is an argmax over the output distribution — the winning token is appended, fed back in, and the process repeats until the model emits an end-of-sequence token or hits a length limit. Nothing is held in reserve, so there is one forward pass per token and no bookkeeping: the fastest decoding there is. It is also fully deterministic, which makes it the strategy to use when you are debugging a model rather than showing it off.

The cost of never looking back
Greedy decoding is myopic. The most probable first word can commit the model to a continuation it would never have chosen as a whole sentence, and there is no mechanism to undo that choice. Two symptoms follow:

  • Lower total sequence probability than beam search finds, with a measurable BLEU gap on translation.
  • Degenerate repetition, where the model loops because the locally safest token is the one it just used.

Where it still belongs
For short, constrained output — a label, an extracted field, a one-line answer — the search barely matters and the latency does. In Hugging Face Transformers, generate() runs greedy decoding whenever sampling is off and the beam count is one, which makes it the baseline every richer strategy is measured against.

Greedy decoding generates text by taking the single highest-probability token at each step and appending it, with no alternatives kept in reserve and no way to revise an earlier choice. It is the fastest decoding strategy and the only fully deterministic one, which makes it the baseline others are measured against. Because every choice is local, a likely first token can commit the model to a poor continuation — the myopia that beam search and sampling methods exist to relieve.

Imagine writing a sentence where you must always pick the word that feels most obvious next, and you are never allowed to go back and change it. You would get something readable, but now and then you would paint yourself into a corner.

That is greedy decoding. Software that writes text chooses one word at a time, and this is the plainest rule for choosing: always take the most likely option. It is quick, cheap, and gives exactly the same answer every time you ask, which is handy when you want predictability. The catch is that the obvious next word sometimes leads nowhere good, and this method has no way to take it back — which is why richer approaches keep a few options open instead.