Top-K Sampling

Category: NLP / Language Processing

A text generation method that restricts sampling to the K most probable tokens at each step, then samples from this reduced distribution.

Full Explanation

Top-K sampling addresses the issues of greedy decoding and pure random sampling by restricting the candidate pool to the K tokens with the highest probabilities, then redistributing the probability mass among them. This prevents the model from selecting very unlikely tokens while maintaining diversity in generation. Typical values of K range from 10 to 100. A major limitation is that the optimal K value varies depending on the probability distribution at each step: when the model is confident, even K=10 may include unlikely tokens; when uncertain, K=10 may exclude reasonable options. This fixed-K limitation motivated the development of nucleus sampling (top-p), which dynamically adjusts the candidate pool size. Top-K sampling remains widely used in practice and can be combined with temperature scaling and other techniques.

Related Terms

More in NLP / Language Processing

Explore More