Skip to content

Sampling temperature

Also called: temperature parameter, temperature setting

Published:

What does sampling temperature change?

At each step a language model assigns probabilities to candidate tokens and picks one. Google Cloud's Vertex AI documentation describes temperature as the setting that controls the degree of randomness in that choice [1]. Lower temperatures suit prompts that need a less open-ended or creative response; higher ones can lead to more diverse or creative results [1].

Anthropic's glossary draws the same line. Higher values bring more variation in phrasing and, in fiction, in the answers themselves, while lower values produce more conservative output that sticks to the most probable wording [2].

A concrete case: if you are asking for product slogans, raising the temperature gets you a different set on each try. If you are pulling an amount and a date out of an invoice, a low temperature makes it more likely that the same document gets the same answer every time.

Does temperature 0 always give the same output?

Not quite. The Vertex AI documentation says that at 0 the highest-probability token is always selected, so responses are mostly deterministic, though small variations can still occur [1]. Anthropic likewise notes that even at temperature 0 results are not fully deterministic and identical inputs may produce different outputs across API calls [2].

How does it work with top-K and top-P?

Top-K and top-P are separate settings that narrow down the candidate tokens. According to the Vertex AI documentation, temperature is applied when sampling from whatever candidates remain after those filters [1]. Changing all three at once makes the effect hard to read, so adjusting one at a time is usually enough.

Frequently asked questions

Does a higher temperature make a model more accurate?

No. It only makes output more varied; factual tasks usually call for a low value.

Is temperature 0 fully deterministic?

No. Providers note that small differences can still appear between identical requests.

Sources

  1. Experiment with parameter values — Google Cloud
  2. Glossary — Claude Docs