A language model doesn’t output text directly. At each step it outputs a probability for every token in its vocabulary, and a decoding strategy decides which token to actually emit. The same model can write flat, repetitive prose or varied, fluent text depending only on this choice.
Search: aim for the most likely text
- Greedy decoding always takes the single most likely token. It is fast and deterministic, but it can miss a better sentence that starts with a less likely word.
- Beam search keeps several candidate sequences alive and returns the one with the highest overall probability. It suits tasks with one right answer, such as translation.
Sampling: draw from the distribution
- Temperature rescales the probabilities before sampling: below 1 makes likely tokens more likely, above 1 flattens the choice.
- Top-k samples only from the k most likely tokens.
- Top-p, or nucleus sampling, samples from the smallest set of tokens whose probabilities add up to p, so the shortlist grows when the model is unsure and shrinks when it is confident.
Repetition penalties, stop sequences and length limits are layered on top.
Why the most likely text isn’t the best
Holtzman et al. found that maximizing likelihood during decoding produces text that is “bland and strangely repetitive”, even from a strong model. Human writing is not made of the most probable word at every step. Sampling while cutting off the unreliable low-probability tail, which is what top-p does, produced text closer to human writing. That is why chat assistants generally sample, while tasks that want a single exact answer lean on greedy or beam search.