Foundations of Top-Decoding For Language Models

Georgy Noarov, Soham Mallick, Tao Wang, Sunay Joshi, Yan Sun, Yangxinyu Xie, Mengxin Yu, Edgar Dobriban · OpenReview

Abstract: Top-$k$ decoding is a widely used method for sampling from LLMs: at each token, only the largest $k$ next-token-probabilities are kept, and the next token is sampled after re-normalizing them to sum to unity. Top-$k$ and other sampling methods are motivated by the intuition that true next-token distributions are sparse, and the noisy LLM probabilities need to be truncated. However, to our knowledge, a precise theoretical motivation for the use of top-$k$ decoding is missing. In this work, we develop a theoretical framework that both explains and generalizes top-$k$ decoding. We view decoding at a fixed token as the recovery of a sparse probability distribution. We consider Bregman decoders obtained by minimizing a separable Bregman divergence (for both the primal and dual cases) with a sparsity-inducing $\ell_0$ regularization. Despite the combinatorial nature of the objective, we show how to optimize it efficiently for a large class of divergences. We show that the optimal decoding strategies are greedy, and further that the loss function is discretely convex in $k$, so that binary search provably and efficiently finds the optimal $k$. We show that top-$k$ decoding arises as a special case for the KL divergence, and identify new decoding strategies that have distinct behaviors (e.g., non-linearly up-weighting larger probabilities after re-normalization).

Introduction

Large Language Models (LLMs) generate text by predicting a probability distribution over a vast vocabulary. However, sampling directly from this raw distribution often results in incoherent text because the model assigns non-zero probabilities to highly unlikely tokens—the so-called "unreliable tail." To mitigate this, practitioners rely on heuristic truncation methods like top-$k$ or top-$p$ sampling. Despite their ubiquity, these methods have lacked a rigorous theoretical foundation. This work addresses this gap by framing decoding as a sparse optimization problem using Bregman divergences, providing a principled explanation for top-$k$ decoding and introducing a new family of adaptive strategies.

Regularized Sparse Bregman Decoding

The proposed framework treats decoding as a signal recovery problem: finding a sparse probability distribution $\hat{p}$ that optimally approximates the raw model output $p$. This is formulated as minimizing a Bregman divergence subject to an $\ell_0$ penalty that encourages sparsity:

$$\text{minimize}_{\hat{p}} \text{Div}(\hat{p}, p) + \lambda \|\hat{p}\|_0$$

Bregman divergences are a generalized class of distance measures that include squared Euclidean distance and Kullback–Leibler (KL) divergence. By exploring both primal and dual forms of these divergences, the authors identify a broad family of decoders. A key contribution is the introduction of $\alpha$-Bregman decoding, based on Tsallis $\alpha$-entropies. This family is highly flexible: when $\alpha=1$, the framework recovers standard top-$k$ decoding. Other values of $\alpha$ lead to novel behaviors, such as "water-filling" effects or non-linear up-weighting of high-probability tokens.

Figure 1: Comparison of probability distributions for different decoding strategies. Bregman-α decoding can produce sparser or more uniform distributions than standard top-k depending on the value of α.

Theoretical Insights

The framework provides several critical theoretical justifications for existing practices:

  • Top-$k$ as Optimal KL-Projection: The authors prove that standard top-$k$ decoding is the exact solution to the sparse projection problem when using the KL divergence. This establishes top-$k$ as a mathematically optimal estimator rather than just a heuristic.
  • Optimality of Greedy Selection: The paper proves that for a large class of "valid" Bregman generators, the optimal sparse distribution always consists of the top-$k$ most likely tokens. This justifies the "greedy" nature of truncation methods.
  • Discrete Convexity and Efficiency: Despite the combinatorial nature of $\ell_0$ optimization, the objective function is shown to be discretely convex in $k$. This allows the optimal $k$ to be found efficiently via binary search in $O(\log k^*)$ time, enabling adaptive decoding where $k$ changes per token based on model confidence.
Figure 5: Renormalization behavior of different Bregman-α decoders. Unlike standard top-k (α=1), other values of α non-linearly re-weight the probabilities.

As shown in Figure 5, Bregman decoders can "warp" the renormalized probabilities. While standard top-$k$ (equivalent to $\alpha=1$) performs linear rescaling, other $\alpha$ values can aggressively favor the top token or flatten the distribution, effectively combining truncation with temperature-like scaling in a single optimization step.

Experimental Evaluation

The framework was evaluated using models such as GPT-2, Llama 3.1, and Qwen 2.5 across benchmarks including WebText, GSM8K, and TriviaQA.

  • Reasoning and Accuracy: On the GSM8K math benchmark, adaptive Bregman decoding maintained or improved accuracy compared to fixed top-$k$, particularly in high-temperature settings where standard sampling often fails.
  • Generation Quality: In open-ended text generation (WebText), specific decoders (e.g., $\alpha=2.0$, corresponding to the Brier score) significantly reduced repetitive token generation compared to standard methods.
  • Computational Efficiency: The binary search approach for finding the optimal $k$ proved computationally cheap, making it viable for real-time inference.

Conclusion and Future Work

This work provides the first formal theoretical foundation for top-$k$ decoding, elevating it to a principled optimization method. By generalizing this to the Bregman family, the authors open new avenues for adaptive, mathematically grounded sampling. Future research will explore extending this framework to other popular heuristics like top-$p$ (nucleus) and min-$p$ sampling, as well as investigating optimal scaling laws for the sparsity parameter $\lambda$.

Summary updated

BibTeX
@inproceedings{noarov2025foundations,
  author = {Georgy Noarov and Soham Mallick and Tao Wang and Sunay Joshi and Yan Sun and Yangxinyu Xie and Mengxin Yu and Edgar Dobriban},
  title = {{Foundations of Top-Decoding For Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=G7CiAs8xyw},
}
Figure