Nucleus sampling (top-p) eliminated both the endless repetition loops of beam search and the incoherent tail noise of pure sampling by dynamically sizing the candidate vocabulary to capture a fixed share p of probability mass at every token. Ari Holtzman, Jan Buys, Li Du, Maxwell Forbes, and Yejin Choi (University of Washington, AI2, and University of Cape Town; ICLR 2020) proved that human language does not maximize likelihood, and that a 0.95 cumulative mass cutoff matches human perplexity (13.13 vs 12.38), diversity, and vocabulary statistics far more faithfully than greedy decoding, beam search, temperature scaling, or fixed top-k.
Open-ended generation exposes a sharp paradox in autoregressive language models: models trained to maximize token likelihood produce high-quality probabilities, yet decoding to maximize sequence likelihood yields robotic repetition. On GPT-2 Large (762M parameters), greedy decoding fell into repetition loops 73.66% of the time and beam search (b=16) repeated 28.94% of the time, compared to 0.28% in human WebText. Nearly every modern LLM API still exposes top_p alongside temperature because the shape of the next-token distribution swings wildly from word to word.
- Matches human perplexity and diversity: At
p=0.95, GPT-2 Large hits 13.13 perplexity (human 12.38), 0.32 Self-BLEU4 (human 0.31), 0.95 Zipf coefficient (human 0.93), and 0.36% repetition (human 0.28%). - Highest human-statistical score: Nucleus sampling achieves 0.97 on HUSE (combining 4,000 human typicality ratings per method with LM likelihood), beating
top-k=640(0.94), greedy (0.79), pure sampling (0.19), andtop-k=40, t=0.7(0.08). - Pure sampling’s unreliable tail: Sampling from the full vocabulary inflates perplexity to 22.73 because tens of thousands of tiny tail probabilities accumulate enough combined mass to inject nonsense tokens (even inventing words like
"umidauda"). - Large beams collapse into silence: At beam width
b >= 64, both GPT-2 Large (774M) and GPT-2 XL (1,542M) assign highest probability to stopping immediately after the prompt.
Why maximizing probability produces robotic loops
A natural first hypothesis is that beam search repeats itself because it fails to find the highest-scoring human sentence (a search error). Holtzman and colleagues ruled that out directly. Plotting per-token probabilities across 100-token passages (Figure 2), they showed that human prose continuously dips into lower-probability, informative words while beam search hugs an unnaturally flat high-probability ridge: beam search (b=16) scores 1.48 perplexity and greedy scores 1.50, nearly an order of magnitude below the 12.38 perplexity of actual human text.
They tie this to Grice’s Maxims of Communication: speakers avoid stating the completely obvious, so natural language spends very little time at maximal next-token likelihood. Because autoregressive models factor text left-to-right token by token without a global coherence objective, maximizing local probability systematically favors generic clichés and creates a self-reinforcing repetition feedback loop (Figure 4). Every time a phrase like "I don't know." repeats in context, the Transformer’s attention copies that pattern and pushes the conditional probability of repeating it a fourth or fifth time closer to 1.0.
Even increasing beam width fails to fix the problem. While Figure 9 shows loop rate dropping superficially as b grows, Appendix A (Figure 10) reveals why: average generation length shrinks linearly with beam width while distinct trigrams remain tiny and flat, until at b >= 64 GPT-2 Large and XL prefer emitting end-of-text almost immediately.
The nucleus algorithm and why fixed top-k misses the mark
Pure sampling sits at the opposite extreme. Across a 50,257-token BPE vocabulary, individual tail words carry tiny probabilities like 0.00001. Multiplied across tens of thousands of candidates, that “unreliable tail” commands substantial aggregate mass. Once a stray tail token gets sampled, the model conditions on gibberish and drifts further off the rails (Figure 1’s "Cosplaying as the Bolivian Cavalleros" and Figure 3’s invented word "umidauda").
Fixed top-k sampling attempted to chop off the tail by keeping only the k highest-scoring tokens at every step. Yet any single integer k breaks across alternating context shapes (Figure 5):
- In flat contexts (such as starting a new sentence or picking a noun), valid probability mass spreads evenly across hundreds of candidates. Setting
k=40clips legitimate choices, drops perplexity to 6.88, and raises Self-BLEU4 to 0.39 (less diverse than human 0.31). - In peaked contexts (where one word holds 90% mass), raising
k=640to fix diversity forces 639 improbable tokens into the sampling set and boosts their rescaled probabilities. Even worse, the rescaling denominatorp'fluctuates wildly from step to step undertop-k.
Nucleus sampling replaces the fixed token count k with a probability mass threshold p. At each step, sort tokens descending by probability and define the nucleus V^(p) as the smallest prefix whose cumulative probability meets or exceeds p. Compute p' = sum_{x in V^(p)} P(x | x_{1:i-1}), zero out everything outside V^(p), and rescale the kept tokens by 1 / p'.
When the model is confident, V^(p) automatically shrinks to 1 or 2 tokens; when the next word is genuinely open-ended, V^(p) expands smoothly to hundreds of candidates while never touching the long tail and keeping the renormalization factor p' tightly bounded near p.
Compare all five decoding families side by side
Step through the five decoding families tested on 5,000 GPT-2 Large continuations (up to 200 tokens seeded by 1 to 40 WebText tokens) to compare exact quantitative metrics, HUSE quality-diversity scores, and failure examples.
Select a decoding method (or use Left and Right arrow keys) to compare its exact Table 1 metrics, HUSE rating, and failure or success pattern.
Nucleus sampling (p = 0.95)
ProposedAdapts shortlist size per token to hold at least 95% mass, matching human perplexity, vocabulary spread, and HUSE score.
- Table 1 metrics
- Perplexity 13.13 (human 12.38), Self-BLEU4 0.32 (human 0.31), Zipf coefficient 0.95 (human 0.93), and repetition 0.36% (human 0.28%).
- HUSE human+stat score
- 0.97 (highest of all tested strategies across 4,000 human annotations per method combined with LM probability).
- Why the mechanism works
- Expands to hundreds of valid choices in open clauses and collapses to 1 or 2 tokens on idioms, cutting the tail without clipping flat heads.
- Observed limitation
- On the Figure 3 stranded-whales prompt, it remains coherent and natural yet still drifts factually from whales to petrel birds.
Greedy decoding and Beam Search (b = 16)
MaximizationOptimizing sequence probability pushes perplexity far below human levels and traps generations in verbatim loops.
- Why maximization breaks
- Perplexity collapses to 1.50 (greedy) and 1.48 (beam b=16), driving repetition to 73.66% and 28.94% while Self-BLEU4 rises to 0.50 and 0.44.
- Feedback loop effect
- Figure 4 proves repeating a phrase boosts its own next-token probability toward 1.0 on each pass, making loops self-sustaining.
- Large-beam collapse
- At b >= 64 on GPT-2 Large and XL, the highest-scoring continuation is stopping immediately right after the prompt.
- HUSE human+stat score
- Greedy hits 0.79 (not measured for beam b=16 in Table 1), penalized for low diversity despite grammatical phrasing.
Pure sampling (t = 1.0) and temperature (t = 0.9)
UntruncatedSampling without truncation captures human diversity and Zipf slope (0.93) but draws garbage from the long tail.
- Why untruncated fails
- Perplexity balloons to 22.73 (almost double human 12.38) as tens of thousands of tail tokens collectively trigger off-topic hallucinations.
- HUSE human+stat score
- 0.19 for pure sampling (worst among untruncated runs), showing human raters immediately spot incoherent tail drift.
- Temperature t=0.9 effect
- Lowering temperature to 0.9 pulls perplexity to 10.25 and repetition to 0.66%, yet Self-BLEU4 rises to 0.35 and loops climb sharply below t=0.9.
- Stochastic beam (b=16)
- Gumbel-top-k stochastic beam raises perplexity to 19.20 while lowering repetition to 0.32%, still trailing nucleus coherence.
Fixed Top-k (k = 40, k = 640, and k = 40 with t = 0.7)
Fixed countSmall k sacrifices diversity while large k leaks tail noise; pairing k=40 with t=0.7 triggers repetition.
- Why fixed k breaks
- k=40 drops perplexity to 6.88 (too predictable, Self-BLEU4 0.39); k=640 matches diversity (0.32, HUSE 0.94) yet shoots perplexity up to 13.82.
- The GPT-2 blog preset trap
- k=40 combined with t=0.7 yields perplexity 3.48, Self-BLEU4 0.44, 8.86% repetition, and the lowest HUSE score in Table 1 (0.08).
- Qualitative failure
- In Figure 3, k=640 jumps abruptly from stranded whales to a pumping station URL, while k=40, t=0.7 repeats the same whale sentence twice.
- Rescaling instability
- Because the truncated mass p' varies wildly between flat and peaked tokens under fixed k, token selection becomes poorly calibrated.
Source: Holtzman et al. (2020), Section 4 through Section 6 and Table 1.
If you prefer the short version without clicking through each tab, Table 1 and HUSE separate the methods cleanly:
- Nucleus sampling (
p=0.95): Hits the closest match to human text on perplexity (13.13 vs 12.38), Self-BLEU4 (0.32 vs 0.31), repetition (0.36% vs 0.28%), and wins HUSE (0.97). - Greedy and beam search: Crush perplexity (1.50 / 1.48) and lock into verbatim repetition loops (73.66% / 28.94%), or stop early once
b >= 64. - Pure and temperature sampling: Untruncated sampling produces rare-word gibberish (22.73 perplexity, 0.19 HUSE), while dropping temperature below
0.9reintroduces repetition. - Fixed
top-k: Smallk=40(especially witht=0.7, hitting 8.86% repetition and 0.08 HUSE) over-constrains flat contexts, whereas largek=640leaks junk into peaked contexts.
Caveats and how decoding evolved after GPT-2
Three caveats keep this 2020 result in proper perspective for modern systems.
First, nucleus sampling solves open-ended generation, not constrained or factual tasks. The authors draw a clear line in Section 2.2 between directed generation (translation, summarization, structured extraction) and open-ended continuation. When a pipeline needs deterministic JSON schemas, strict code syntax, or grounded extraction, injecting top-p=0.95 randomness increases factual drift, just as GPT-2 drifted from stranded whales to petrel birds in Figure 3.
Second, the HUSE evaluation required a smoothing workaround. Strict truncation assigns zero probability to pruned tail tokens, which originally collapsed top-k and nucleus HUSE scores near zero because the statistical discriminator spotted zero-likelihood events. To measure HUSE cleanly in Table 1, the authors interpolated the truncated distribution with 0.1 mass from the raw model distribution during scoring.
Third, these benchmarks ran on an unaligned pretrained model (GPT-2 Large) before RLHF. Reinforcement learning from human feedback and instruction fine-tuning concentrate probability mass far more sharply than raw WebText pretraining, reducing raw tail noise while creating new issues like length bias and mode collapse. Even so, top-p remains standard across every production inference stack, pairing naturally with speculative decoding (which treats nucleus truncation as a standardized distribution before draft verification) on top of Transformer attention, BPE tokenizers, and tied output embeddings.
For engineers configuring LLM decoding today, the lesson is straightforward: never tune temperature and top_p blindly to zero for open-ended writing, and never treat top_k as a universal cutoff. Use top_p (typically 0.90 to 0.95) when you want natural, non-repetitive prose with adaptive headroom, and drop toward low temperature or greedy decoding only when output structure and determinism matter more than variety.


