Truncation Sampling as Language Model Desmoothing

John Hewitt, Christopher D. Manning, Percy Liang

Abstract

Neural language models (LMs) are typically trained using the Kullback-Leibler (KL) divergence objective, which encourages them to be "mode-covering." This training objective forces models to assign non-zero probability to nearly all tokens in the vocabulary to avoid infinite loss, resulting in a "smoothed" distribution that includes low-quality noise in the tail. This paper reframes truncation sampling—such as top-$k$ and top-$p$—as a process of desmoothing, an attempt to recover the true underlying distribution by filtering out this noise. We introduce $\eta$-sampling, a new algorithm that utilizes an entropy-dependent threshold to generate more coherent and less repetitive long-form text.

Introduction

When generating text from large language models (LLMs), practitioners rarely sample directly from the raw output probabilities. Direct sampling often leads to the selection of highly improbable "noise" tokens, which can derail the generation into nonsense or repetitive loops. To mitigate this, truncation heuristics like top-$k$ (limiting selection to the $k$ most likely tokens) or top-$p$ / Nucleus Sampling (limiting selection to the smallest set of tokens whose cumulative probability exceeds $p$) have become standard.

However, these heuristics are often applied without a theoretical grounding in why the noise exists. This research argues that these methods are flawed because they do not account for the systematic "smoothing" inherent in the training process. By understanding truncation as a desmoothing operation, we can develop more principled sampling methods that adapt to the model's local confidence.

The Problem: Training-Induced Smoothing

LLMs are trained to minimize KL-divergence between the model distribution and the data distribution. Because the model is penalized heavily for assigning zero probability to a word that appears in the training data, it becomes "mode-covering." Consequently, the model spreads a small amount of probability mass over thousands of irrelevant or noisy tokens.

Current truncation methods often fail to handle this smoothing correctly across different contexts:

  • Over-truncation in Low-Entropy Settings: In predictable contexts (e.g., the prompt "Donald..."), top-$p$ might assign 96% probability to "Trump" and truncate all other valid continuations like "Duck" or "Glover," even though they are perfectly plausible. This destroys the model's inherent creativity.
  • Under-truncation in High-Entropy Settings: In unpredictable contexts, top-$p$ may allow too much noise to pass through, leading to incoherent generations.

Proposed Method: $\eta$-Sampling

The authors propose a framework where the neural LM is viewed as a mixture of a true distribution and a uniform-like smoothing distribution. The goal of truncation is to "desmooth" the model to recover the support of the true distribution. This leads to two core principles for a better truncation algorithm:

  1. Absolute Probability: Tokens with high absolute probability should rarely be truncated.
  2. Relative Probability: In high-entropy (uncertain) situations, the truncation threshold should be lower but remain relative to the rest of the distribution.

This results in $\eta$-sampling (eta-sampling). Unlike top-$p$, which adjusts the number of tokens based on cumulative mass, $\eta$-sampling sets a probability threshold $\eta$ based on the entropy ($h$) of the distribution: $$\eta = \min(\epsilon, \alpha \cdot \exp(-h))$$

By scaling the cutoff with entropy, $\eta$-sampling ensures that the model does not over-truncate when it is certain and appropriately filters noise when it is uncertain.

Experimental Evaluation

The researchers evaluated $\eta$-sampling using the GPT-2 family (Small through XL) to ensure the findings scaled with model size. They utilized the WebText dataset for hyperparameter tuning and the evaluation of open-ended generation.

Key Results

  • Human Preference: In a head-to-head study regarding long-document plausibility, human evaluators preferred $\eta$-sampling over top-$p$ (53% to 39%).
  • Breaking Repetition: Truncation failures often manifest as repetitive loops. In adversarial tests, $\eta$-sampling was significantly more effective at breaking these cycles. For GPT-2 XL, $\eta$-sampling reduced the repetition rate to 12%, compared to 27% for top-$p$.
  • Statistical Quality: $\eta$-sampling achieved comparable or superior MAUVE scores, indicating that the generated text closely mirrors the distributional properties of human-written text.
  • Entropy Balance: Analysis showed that $\eta$-sampling strikes a superior balance compared to previous methods, avoiding the aggressive over-truncation of low-entropy distributions seen in top-$p$ and the under-truncation of high-entropy distributions seen in $\epsilon$-sampling.

Conclusion and Future Work

By framing truncation as "desmoothing," this work provides a theoretical justification for a common practice in NLP. $\eta$-sampling offers a more principled approach to text generation that preserves diversity in predictable contexts while maintaining coherence in uncertain ones.

Future research may explore the application of $\eta$-sampling to languages with richer morphology, which may exhibit different distributional properties. Additionally, while $\eta$-sampling improves word-by-word generation, the long-term sequence-level effects of truncation remain a complex area for future study in model safety and fairness.

Summary updated

BibTeX
@inproceedings{hewitt2022truncation,
  author = {John Hewitt and Christopher D. Manning and Percy Liang},
  title = {{Truncation Sampling as Language Model Desmoothing}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.findings-emnlp.249},
}
Figure