Closing the Curious Case of Neural Text Degeneration

Matthew Finlayson, John Hewitt, Alexander Koller, Swabha Swayamdipta, Ashish Sabharwal

The Problem: Degeneration and the Truncation Heuristic

When generating text, Large Language Models (LLMs) do not simply pick the single most likely next word; they sample from a probability distribution over their entire vocabulary. However, "ancestral sampling"—sampling directly from this raw distribution—often leads to "degeneration," producing text that is repetitive, incoherent, or nonsensical.

To combat this, researchers rely on truncation heuristics like Top-K or Nucleus (Top-P) sampling, which chop off the "tail" of the distribution. While these methods are incredibly effective in practice, their mathematical necessity has historically been poorly understood. Furthermore, these methods are "coarse": they use a simple probability cutoff, which might accidentally discard a rare but contextually perfect word while keeping a high-probability word that is actually a model error.

This paper provides the first rigorous mathematical explanation for why truncation sampling is so effective at preventing LLM degeneration. By identifying the "softmax bottleneck" as a primary source of model error, the authors introduce Basis-Aware Threshold (BAT) sampling, a method that uses linear algebra to more precisely distinguish between valid low-probability tokens and erroneous ones.

Methods: The Softmax Bottleneck and BAT Sampling

The authors tackle the text degeneration problem through two primary lenses:

  1. Theoretical Proof of Truncation: They prove that if a model’s log-probability errors are bounded, threshold-based truncation is mathematically guaranteed to only sample tokens that exist in the "true" underlying distribution. Essentially, truncation acts as a necessary filter for model noise.
  2. The Softmax Bottleneck: They point to a known architectural limitation: the "softmax bottleneck." Because the internal "hidden" layer of an LLM is much smaller than its vocabulary, the model is mathematically incapable of representing certain complex distributions. This causes the model to "smear" probability onto incorrect tokens.

To address this, the authors propose Basis-Aware Threshold (BAT) Sampling. Instead of a flat probability cutoff, BAT uses the mathematical structure of the model's output layer (the softmax matrix). It uses Linear Programming (LP) to check if a token's probability could actually be zero in the "true" distribution given the model's constraints. If the math dictates a token must have non-zero true probability, BAT keeps it—even if its model-assigned probability is very low.

An illustration of non-monotonic selection, where BAT sampling accepts lower-probability tokens while rejecting some higher-probability ones based on the model's mathematical structure.

To make this practical for real-time generation, they use Singular Value Decomposition (SVD) to compress the large matrices, reducing the computation time from minutes to about 0.1 seconds per token.

Key Insights

  • Truncation as "Desmoothing": The paper suggests that LLMs naturally "over-smooth" their predictions, assigning too much probability to "impossible" tokens. Truncation isn't just a hack; it's a necessary correction for this specific type of error.
  • Non-Monotonic Selection: Standard truncation is monotonic—if you keep a token with 1% probability, you must keep all tokens with >1%. BAT is non-monotonic. It can reject a high-probability "bad" token while keeping a lower-probability "good" one because it looks at the linear dependencies between token embeddings.
  • The Bottleneck is the Key: The success of BAT provides direct evidence that the softmax bottleneck is a major reason why LLMs need truncation in the first place. By accounting for this bottleneck, we can "surface" the model's true capabilities more effectively.

Results and Evaluation

The researchers evaluated their approach using the GPT-2 family (Small, Medium, Large, and XL) on the OpenWebText (OWT) corpus. They measured performance using MAUVE (a metric that measures how close generated text is to human text) and pairwise human evaluations.

Examples of BA-η sampling across different prompts, demonstrating how it dynamically accepts (blue) or rejects (orange) tokens compared to standard threshold cutoffs.
  • Superior Performance in Low-Entropy Settings: BAT (specifically the BA-$\eta$ variant) consistently outperformed standard truncation methods in "low-entropy" generation, where the model is being more conservative or greedy.
  • MAUVE Gains: On GPT-2 Large, BA-$\eta$ achieved significantly higher MAUVE scores than standard $\eta$-sampling or Nucleus sampling.
  • Human Preference: Human annotators narrowly preferred text generated by BAT, finding it more coherent than standard threshold-based methods.
  • Scaling Benefits: The benefits of BAT were more pronounced as the model size increased, suggesting this approach remains highly relevant as LLMs grow.

Limitations and Future Work

While promising, BAT sampling introduces computational overhead. Even with SVD optimizations, solving a linear program is significantly slower than a simple Top-P cutoff. Additionally, the current version of BAT doesn't pair well with Nucleus sampling; it works best as an enhancement to $\epsilon$ or $\eta$ sampling.

In very restrictive settings, BAT can occasionally "reject" all possible tokens, requiring a fallback strategy (like greedy decoding) that hasn't been fully optimized yet. Finally, while the study focused on GPT-2, future work is needed to see how BAT performs on modern, massive architectures like Llama 3 or GPT-4, which may exhibit different bottleneck characteristics.

Summary updated

BibTeX
@inproceedings{finlayson2024closing,
  author = {Matthew Finlayson and John Hewitt and Alexander Koller and Swabha Swayamdipta and Ashish Sabharwal},
  title = {{Closing the Curious Case of Neural Text Degeneration}},
  booktitle = {International Conference on Learning Representations},
  year = {2024},
  url = {https://openreview.net/forum?id=dONpC9GL1o},
}
Figure