Learn AI Math

Temperature

What is Temperature?

In one sentence: Temperature is a setting that controls how random or creative a model's answers are.

When choosing the next token, the model has a list of options with different chances. Low temperature makes it almost always pick the most likely option, so answers are focused and predictable. High temperature makes it more willing to pick less likely options, so answers are more varied and creative, but sometimes weird.

Σ Quick math / rule of thumb: T = 0 picks the single highest-probability token (greedy); T = 0.2–0.4 stays focused for code/facts; T = 0.8–1.0 flattens probabilities for creative variety.

What does Temperature look like?

Temperature 0 is good for math or facts, while temperature 0.9 is better for brainstorming story ideas.

Why does Temperature matter?

Adjusting temperature lets you trade reliability for creativity.

Temperature vs. Top-P Sampling

Temperature rescales how flat or sharp all token probabilities are, while Top-P (nucleus sampling) cuts off the unlikely tail once top choices add up to probability P.

DimensionTemperatureTop-P Sampling
MechanismSharpens (<1) or flattens (>1) logitsKeeps smallest top set summing to P (e.g., 0.9)
Effect on long tailLowers tail odds but keeps rare words possibleHard-truncates low-probability tail tokens
Practical adviceTune one primarily (e.g., T=0.2 for code, 0.8 for writing)Keep near 0.9–0.95 as a safety net

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.