# Top-k Sampling

> Top-k sampling is a decoding method that, at each step, restricts sampling to the k most probable next tokens and renormalizes their probabilities.

- Identifier: PTL-0108
- Category: Foundations
- Canonical URL: https://protologue.com/t/top-k-sampling/
- Also known as: top-k
- Introduced: 2018

## Description

It removes the long tail of unlikely tokens that can derail generation, while keeping some variety. Because k is fixed, it can be too restrictive when many tokens are plausible and too permissive when only one is, which motivated top-p (nucleus) sampling. Many APIs expose top-k alongside temperature and top-p.

## Related terms

- [Temperature](https://protologue.com/t/temperature/)
- [Top-p Sampling](https://protologue.com/t/top-p-sampling/)
- [Greedy Decoding](https://protologue.com/t/greedy-decoding/)

## Comparisons

- [Top-k Sampling vs Top-p Sampling](https://protologue.com/compare/top-k-vs-top-p-sampling/)

## Sources

- Fan et al. (2018). Hierarchical Neural Story Generation. https://arxiv.org/abs/1805.04833
- Holtzman et al. (2019). The Curious Case of Neural Text Degeneration. https://arxiv.org/abs/1904.09751

## Cite this entry

Protologue. (2026). Top-k Sampling. In Protologue: A Taxonomy of Prompting and LLM Techniques (v1.4.0, PTL-0108). https://protologue.com/t/top-k-sampling/

License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
