Locally Typical Sampling

Clara Meister, Tiago Pimentel, Gian Wiher, Ryan Cotterell

Abstract

Standard decoding strategies for Large Language Models (LLMs), such as nucleus or top-k sampling, often struggle with a "probability-quality paradox," where high-probability sequences lead to repetitive or dull text. This paper introduces Locally Typical Sampling, a decoding strategy rooted in the information-theoretic principle of Uniform Information Density. By selecting words whose surprisal matches the model’s conditional entropy, this method produces more coherent, human-like text and significantly reduces degenerate repetitions.

Introduction

Current LLMs excel at predicting the next token, yet the most probable sequences (found via beam search or greedy decoding) are frequently suboptimal for human consumption, often resulting in "degenerate repetitions." Conversely, random sampling can lead to incoherent "word salad." While truncated sampling methods like top-k and nucleus (top-p) sampling mitigate these issues, they do not explicitly account for the information-theoretic properties of human communication. The authors argue that instead of maximizing probability, decoding should aim for typicality—selecting tokens that provide an amount of information consistent with the model's current uncertainty.

Methodology: The Principle of Typicality

Locally Typical Sampling is based on the Uniform Information Density (UID) hypothesis from psycholinguistics, which suggests that humans communicate at a relatively constant information rate. In information theory, the "typical set" contains sequences where the average surprisal is close to the entropy of the source.

The proposed algorithm operates as follows:

  1. Entropy Calculation: At each timestep $t$, the conditional entropy $H(P(x_t | x_{<t}))$ of the model’s distribution is calculated.
  2. Deviation Measurement: For each candidate word, the algorithm computes its "surprisal" (negative log-probability) and determines its deviation from the entropy: $\epsilon = |-\log P(x | x_{<t}) - H|$.
  3. Truncation and Sampling: The algorithm selects a subset of words with the smallest $\epsilon$ until a cumulative probability mass $\tau$ is reached. The final token is then sampled from this "locally typical" subset.

Unlike Nucleus Sampling, which prioritizes the highest probability mass, Typical Sampling may bypass high-probability tokens if they are "too predictable" (low surprisal) relative to the model's current state of uncertainty.

Empirical Validation

To verify the hypothesis that human text follows this typicality pattern, the authors analyzed three datasets: CNN/DailyMail (Abstractive Summarization), WritingPrompts (Story Generation), and WikiText-103.

Distribution of local typicality ($\epsilon$) in human-written text across different datasets.

As shown in the figure above, human-generated text consistently clusters around a deviation of zero from the model's entropy. This empirical evidence supports the core premise of the paper: human language is characterized by "local typicality," and decoding strategies should explicitly target this zone to achieve human-like output.

Key Insights and Results

The Bias Coin Analogy

The authors illustrate the concept using a biased coin (60% heads). While the most likely sequence of 100 flips is 100 heads, a typical sequence—and what a human would expect—contains roughly 60 heads. Similarly, human language does not always follow the path of maximum probability.

Performance and Human Preference

  • Repetition Reduction: Typical sampling consistently outperformed nucleus and top-k sampling in reducing "degenerate repetitions" (measured by the REP metric).
  • Human Evaluation: Blind tests on Amazon Mechanical Turk showed that humans rated text generated via typical sampling as comparable to or better than standard methods in terms of coherence, fluency, and interestingness.
  • Hyperparameter Robustness: Typical sampling is less sensitive to its hyperparameter $\tau$ than nucleus sampling is to $p$, maintaining low repetition rates across a broader range of settings.

Conclusion

Locally Typical Sampling offers a theoretically grounded alternative to heuristic-based truncation methods. By aligning decoding with the information-theoretic signatures of human speech, it provides a robust mechanism for generating high-quality, non-repetitive text. Future work may explore deterministic variants, such as "typical beam search," to combine the benefits of structured search with the constraints of linguistic typicality.

Summary updated

BibTeX
@article{meister2023locally,
  author = {Clara Meister and Tiago Pimentel and Gian Wiher and Ryan Cotterell},
  title = {{Locally Typical Sampling}},
  journal = {Trans. Assoc. Comput. Linguistics},
  year = {2023},
  doi = {10.1162/tacl\_a\_00536},
}
Figure