# Top-K Sampling

- **Canonical URL:** https://getaimath.com/dictionary/top-k-sampling/
- **Topics:** [LLM Fundamentals](https://getaimath.com/dictionary/category/llm-fundamentals/)
- **Last updated:** 2026-11-25

## What is Top-K Sampling?

**In one sentence:** Top-K sampling means the model only chooses the next token from its K most likely options.

If K is 40, the model looks at its 40 best guesses and picks one of them, ignoring everything else. This stops it from choosing very unlikely, strange words while still allowing some variety.

![How ChatGPT & Claude Talk: Super-Powered Autocomplete — Simple cartoon diagram showing a sentence chopped into Lego word blocks (tokens), an AI brain weighing the odds of the next word ("mat" 75%, "couch" 18%, "roof" 5%), and snapping "mat" onto the end of the sentence.](https://getaimath.com/diagrams/llm-fundamentals.png)
*Napkin Diagram (LLM Fundamentals): Language models don’t plan whole essays at once—they play a super-smart game of "guess the very next word" over and over.*

## What is an example of Top-K Sampling?

With K = 3, after "I like to eat," the model might only consider "pizza," "apples" and "pasta."

## Why does Top-K Sampling matter?

Top-K keeps answers sensible while still letting them vary.

## Related Concepts

- [Temperature](https://getaimath.com/dictionary/temperature/): Temperature is a setting that controls how random or creative a model's answers are.
- [Top-P Sampling](https://getaimath.com/dictionary/top-p-sampling/): Top-P sampling means the model picks from the smallest group of likely tokens whose chances add up to P, such as 90%.
- [Chain of Thought (CoT)](https://getaimath.com/dictionary/chain-of-thought-cot/): Chain of Thought is when an AI works through a problem step by step in writing before giving its final answer.
- [Repetition Penalty](https://getaimath.com/dictionary/repetition-penalty/): A repetition penalty is a setting that makes a model less likely to repeat the same words or phrases over and over.
- [Few-shot Prompting](https://getaimath.com/dictionary/few-shot-prompting/): Few-shot prompting is giving an AI a handful of examples in the prompt before asking it to do the task.
- [Logits](https://getaimath.com/dictionary/logits/): Logits are the raw scores a model gives every possible next token before they are turned into probabilities.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/top-k-sampling/)
