Index Ai Academy

Temperature, top-k and top-p, explained visually

Three settings decide how a language model turns probabilities into words. Move them, watch the odds change, then sample.

A language model doesn't choose a word. It gives every word in its vocabulary a probability, and something then has to pick one. These settings change how that happens. The starting odds below are written by hand, and the reshaping and the sampling are real.

Try temperature 0.3, then 2. Then cut the list with top-k or top-p, and press Sample 100 to see the real draws match the bars.

What each setting does

  • Temperature rescales the model's scores before they become probabilities. Below 1, likely words get likelier. Above 1, the odds flatten and unlikely words get real chances.
  • Top-k keeps only the k likeliest words and drops the rest.
  • Top-p keeps the smallest set of top words whose probabilities add up to p, so the list is short when the model is sure and long when it isn't.

Here they apply in that order, and whatever is left is rescaled to add up to 100%.

Choosing values

Use a low temperature when you want the same dependable answer, as when extracting data. Use a higher one when you want variety, as when brainstorming. Very high values mostly add nonsense rather than creativity. Providers offer different settings and ranges, and it's usually enough to change one at a time and look at the results.

Where the probabilities come from

Softmax turns the model's raw scores into probabilities, and temperature works inside it.

Drag a score up and watch probability flow toward it from the others. Then move the temperature.

Learn how this works, properly

A free account opens all 244 lessons, with Python that runs in your browser, saved progress and certificates.

Create a free account