Learn AI Math

Top-K Sampling

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.

What does Top-K Sampling look like?

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.

Last updated · Fact-checked by The AI Math

Linking to this page from a lesson or article?

Like this explanation? Get one every week.

The AI Math newsletter turns confusing AI news into plain English. No hype, no jargon walls.