Skip to content

Top-p Sampling

Method for selecting the next token during generation: the model considers not all words, but the minimal pool of the most probable ones, giving a cumulative probability p.

How It Works

With top_p = 0.9, the model takes the most probable tokens until their cumulative probability reaches 90%, and selects from them. The rest are discarded.

Top-p vs Temperature

Parameter What It Does
Temperature Smooths the probability distribution
Top-p Truncates the tail of low-probability tokens

Often used together: temperature sets the chaos, top-p limits the selection.

In Practice

  • top_p = 1 — disabled;
  • 0.9–0.95 — reasonable balance for creative tasks;
  • lower — more predictable text.

See Also

← All terms