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), and top-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 dynamic top-p beats fixed top-k across peaked and flat contexts
1. Peaked context
Almost all probability sits on 1 or 2 obvious tokens (e.g., completing a fixed phrase).
Fixed top-k pulls in junk; top-p shrinks to 1 or 2
A large fixed k=640 forces hundreds of irrelevant tail tokens into the pool and rescales them upward; p=0.95 stops as soon as cumulative mass crosses 95%.
2. Flat context
Hundreds of nouns, verbs, or topics are genuinely plausible next choices.
Small top-k clips diversity; top-p expands freely
A tight k=40 truncates valid continuations (dropping perplexity to 6.88 and raising Self-BLEU4 to 0.39), whereas top-p widens up to hundreds or a thousand candidates while excluding the flat tail.

Mechanism and Figure 5 intuition from Holtzman et al. (2020), Sections 3.1 and 3.2.

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.

Why earlier decoding strategies fail in open-ended text
Beam search (b=16)

Locks onto repetitive loops (28.94% repetition; 73.66% for greedy) at unnaturally low perplexity (1.48 vs 12.38 human).

Pure sampling (t=1.0)

Draws rare words from the aggregate mass of tens of thousands of tail tokens, derailing coherence and pushing perplexity to 22.73.

Low temperature (t<0.9)

Shrinks tail mass globally without cutting it off, sacrificing diversity and spiking repetition (top-k=40, t=0.7 hits 8.86% repetition).

Quantitative metrics across 5,000 GPT-2 Large generations in Holtzman et al. (2020), Table 1.

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=40 clips 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=640 to fix diversity forces 639 improbable tokens into the sampling set and boosts their rescaled probabilities. Even worse, the rescaling denominator p' fluctuates wildly from step to step under top-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.

Comparing five decoding strategies on GPT-2 Large (762M)

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)

Proposed

Adapts 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.

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.9 reintroduces repetition.
  • Fixed top-k: Small k=40 (especially with t=0.7, hitting 8.86% repetition and 0.08 HUSE) over-constrains flat contexts, whereas large k=640 leaks 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.