Foundations of Top-$k$ Decoding for Language Models

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

The Unreliable Tails of LLMs

When a Large Language Model (LLM) generates text, it outputs a probability distribution over its entire vocabulary for the next token. However, these distributions often suffer from "unreliable tails"—a long list of low-probability tokens that are essentially noise. To prevent the model from sampling this noise and generating gibberish, practitioners rely on heuristics like top-$k$ decoding (keeping only the $k$ most likely tokens) or top-$p$ sampling (nucleus sampling).

While these truncation methods are industry standards, they have historically lacked a rigorous theoretical justification. Why is picking the top $k$ the mathematically "correct" thing to do? And is there a principled way to choose $k$ dynamically for every single generated word? This paper bridges that gap, framing decoding not as a heuristic cutoff, but as a formal signal recovery problem.

Regularized Sparse Bregman Decoding

The authors introduce a framework called Regularized Sparse Bregman Decoding. Instead of arbitrarily slicing off the tail of the distribution, they define the optimal decoded distribution ($\hat{p}$) as the one that minimizes a specific mathematical objective:

$$\min_{\hat{p}} \{ \text{BregmanDivergence}(\hat{p}, p) + \lambda \|\hat{p}\|_0 \}$$

This equation balances two competing goals:

  1. Bregman Divergence: This measures the "distance" between the proposed sparse distribution ($\hat{p}$) and the model's original noisy output ($p$). Standard measures like KL-divergence and Squared Error are specific types of Bregman divergences.
  2. $\ell_0$-regularization ($\|\hat{p}\|_0$): This term applies a penalty ($\lambda$) for every additional token included in the final distribution. This forces the resulting distribution to be sparse, naturally cutting off the tail.

Because Bregman divergences are asymmetric, the authors explore both Primal (minimizing the first argument) and Dual (minimizing the second argument) formulations.

Key Theoretical Insights

By framing decoding as an optimization problem, the authors unlock several major theoretical insights:

  • Top-$k$ is a Special Case: The paper proves that standard top-$k$ decoding is exactly what emerges when you use the KL-divergence as your distance measure in the primal case. This finally provides a mathematical foundation for the industry's most popular decoding heuristic.
  • The Greedy Property: They mathematically prove that for a wide range of Bregman divergences, the optimal sparse distribution must consist of the top-$k$ tokens. This confirms that "greedy" selection is actually the optimal strategy for denoising.
  • Discrete Convexity ($k$-convexity): Optimizing an $\ell_0$ penalty is usually a computationally hard combinatorial problem. However, the authors discovered that the decoding cost is "discretely convex" with respect to $k$. This means the optimal, adaptive $k^*$ for any given token can be found efficiently using binary search in $O(\log V)$ time, rather than checking every possible vocabulary size.

Introducing $\alpha$-Bregman Decoders

Building on this framework, the authors use Tsallis $\alpha$-entropies to create a new family of $\alpha$-Bregman decoders. Here, $\alpha$ acts as a tunable knob that fundamentally changes how probabilities are re-weighted after truncation.

Renormalization behavior of α-Bregman decoders, showing non-linear up-weighting of probabilities based on the chosen α.

Unlike standard top-$k$, which simply renormalizes the remaining probabilities linearly, $\alpha$-Bregman decoders can non-linearly up-weight larger probabilities. High $\alpha$ values lead to "water-filling" (more uniform distributions among the top choices), while low $\alpha$ values concentrate mass heavily on the absolute top tokens.

Probability distributions comparing standard Top-10 decoding with Bregman-α decoders.

Performance and Results

The authors evaluated these new decoding strategies across models like GPT-2 Large, Llama 3.1 8B, and Phi-3, testing them on open-ended generation (WebText), reasoning (GSM8K), and Q&A (TriviaQA).

  • Adaptive $k$ in Action: The framework successfully chooses $k$ dynamically. On math tasks like GSM8K, the optimal $k$ shrinks to 1 or 2 when the model is highly confident, but expands when the model is uncertain, allowing for necessary exploration.
  • Reduced Repetition: In open-ended text generation, decoders with $\alpha=2.0$ (based on the Brier score) significantly reduced the "repetition difference" compared to standard top-$k$. The resulting text was more diverse and less prone to looping.
  • Competitive Accuracy: Across reasoning and factual benchmarks, these theoretically-grounded decoders matched or exceeded the performance of highly-tuned, static heuristics.

Future Directions

While this paper solidifies the foundation for top-$k$ methods, questions remain. The exact trade-offs between Primal and Dual decoders require further exploration. Additionally, the sparsity penalty $\lambda$ currently requires manual tuning; future work could uncover scaling laws to set $\lambda$ automatically based on model size or task complexity. Finally, extending this rigorous framework to explain top-$p$ (nucleus) sampling represents a promising next step for the field.

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-$k$ Decoding for Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=G7CiAs8xyw},
}
Figure