Decoding strategy
A decoding strategy is the rule a language model uses to turn its predicted probabilities for the next token into actual text, for example always taking the likeliest token (greedy decoding) or tracking several candidate sequences (beam search).
A language model does not write words directly. At each step it produces a probability for every token in its vocabulary, given everything written so far. Something then has to choose which token actually goes next, add it to the text and feed the result back in for the following step. That choice is the decoding strategy. The same model with the same prompt can produce noticeably different text depending on how this step is done.
Greedy decoding takes the single most probable token every time. It is fast and deterministic, and it is the default in Hugging Face's Transformers library. Its documentation notes that it works for short outputs but tends to repeat itself on longer ones. It can also miss a good overall sequence that starts with a slightly less likely word, because it never looks back.
Beam search keeps several partial sequences, called beams, at each step and finally returns the one with the highest overall probability. It can find better sequences than greedy decoding, and Hugging Face recommends it for tasks closely tied to an input, such as describing an image or transcribing speech. It still tends towards repetition in open-ended writing.
Sampling picks the next token at random in proportion to its probability, which gives variety. Settings such as temperature, top-k and top-p control how adventurous the draw is. The case for sampling was made in The Curious Case of Neural Text Degeneration by Ari Holtzman and colleagues, posted in April 2019 and published at ICLR 2020. They showed that always maximising probability produces bland, repetitive text, that the decoding strategy alone can change output quality a great deal, and they proposed nucleus sampling as a better alternative.
In practice, most hosted chat APIs expose sampling settings rather than a menu of algorithms, so developers meet decoding mainly through temperature and top-p. Google's documentation notes that a temperature of 0 means the most probable token is always chosen, which amounts to greedy decoding. Techniques such as self-consistency and best-of-N sit one level above: they run a decoding strategy several times and then choose among the results.
Greedy decoding picks the single most probable next token at every step. It is fast and gives the same output each time for the same input, but on long outputs it tends to repeat itself and can miss better sequences that begin with a less likely word. Beam search tracks several candidate sequences at once, extending each one step at a time and keeping only the most probable. At the end it returns the sequence with the highest overall probability. It suits tasks with a fairly clear right answer, such as transcription, more than open-ended writing. Chat products usually sample the next token at random according to the model's probabilities rather than always taking the most likely one. That makes replies more natural and varied, but it also means two runs of the same prompt can differ. Lowering the temperature makes answers more repeatable. It depends on the task. Greedy decoding or a low temperature suits extraction and classification, where consistency matters. Beam search suits input-grounded tasks, and sampling with top-p or top-k suits conversation and creative writing, where variety matters more than a single most likely answer.Common questions
What is greedy decoding?
What is beam search in language models?
Why does a chatbot give different answers to the same question?
Which decoding strategy is best?
Search for "greedy decoding vs beam search", "nucleus sampling" or "text generation strategies" to see how the methods compare. Library documentation such as Hugging Face's generation guides shows each method with working code, and the original research papers on arXiv explain why each was proposed. Provider API documentation is the place to check which settings a particular service actually exposes.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.