Skip to content

Sampling

A generation strategy where the next token is not strictly chosen as the most probable, but randomly according to a probability distribution. This is how models provide lively and varied responses.

How it Works

  1. The model calculates the probability for each token.
  2. A token is selected randomly, but with regard to weights: more probable tokens are selected more often, less probable tokens are selected less often.
  3. The process repeats.

Why It's Needed

Greedy always gives the same answer. Sampling introduces randomness — so the model answers differently to the same question, like a human would.

Controlling Randomness

Parameter What it Does
Temperature "Temperature" stretches or compresses the distribution
Top-k Limits selection to the k most probable tokens
Top-p Limits selection to a pool with cumulative probability p

See Also

← All Terms