Temperature
Also known as: sampling temperature
A per-request dial - low keeps a language model's wording steady and repeatable, high makes it more varied and less predictable.
Draft - this entry has not been reviewed yet.
Formal
A number, usually from 0 to 1 or 0 to 2 depending on the provider, that reshapes the chances from next-token prediction before sampling picks a token; values below 1 sharpen them toward the most likely tokens, values above 1 flatten them so unlikely tokens are picked more often.
In plain English
Like a DJ's shuffle setting - turned down, you mostly hear the crowd favourites; turned up, more rare tracks slip in.
In practice
A developer in a municipality sets temperature near 0 for the tool that reads date and amount from incoming invoices, so the same invoice almost always gives the same result, and near 1 for the one that suggests headlines for the residents' newsletter.
Why it matters
It is one of the few levers you can change per request without touching the model; set wrong, text turns stiff and repetitive or loose and rambling, and even 0 does not promise identical answers every time.
Technical deep dive
Temperature T divides the logits before the softmax: p_i = exp(z_i / T) / Σ_j exp(z_j / T). At T = 1 the model's distribution is unchanged. As T falls toward 0 the distribution sharpens and approaches a one-hot vector on the argmax, so sampling converges to greedy decoding; implementations special-case T = 0 as greedy rather than dividing by zero. As T grows the distribution flattens toward uniform, and the probability mass in the long tail of implausible tokens rises. The name comes from the Boltzmann distribution in statistical mechanics, and the same knob appears elsewhere in machine learning, for example in knowledge distillation (Hinton et al., 2015), where a raised temperature softens a teacher model's outputs.
Temperature changes relative probabilities without changing their order: the most likely token remains the most likely at every T > 0. It interacts with truncation. In most implementations temperature is applied first and top-k, top-p or min-p afterwards, so a high temperature widens the nucleus that top-p keeps, while a low temperature can shrink it to a single token and make top-p irrelevant. That coupling is why providers advise tuning one of the two and leaving the other at its default; Anthropic's API documentation says to alter temperature or top_p but not both, and some newer models reject requests that set both.
Ranges and defaults differ by provider and change over time, so they should be read from the current API reference. OpenAI's Chat Completions API has documented a range of 0 to 2 with a default of 1; Anthropic's Messages API has documented 0 to 1 with a default of 1. Some reasoning models accept only the default value or ignore the parameter, because their reasoning is tuned for a fixed sampling setup. Values numerically equal across providers are not equivalent, since the underlying models' distributions differ.
Common misconceptions: temperature is not a creativity or accuracy dial as such. Low temperature makes output more consistent, not more correct - a model that is confidently wrong stays wrong, and greedy decoding can fall into repetition loops in long outputs. High temperature increases lexical variety but also the rate of factual slips and incoherence, especially in long generations where one improbable token shifts everything after it. And temperature 0 does not guarantee identical outputs on hosted APIs: batching and floating-point reduction order introduce small numerical differences that can flip near-tied tokens. For evaluation, run each test case several times rather than relying on T = 0 for determinism.
What to learn first
Everything this builds on, foundations first.
- Inference
- →Token
- →Next-token prediction
- →Temperature
Relationships
- Part of
- Sampling
- Requires
- Next-token prediction
- Used with
- Top-p sampling
Sources & further reading
Official documentation
- OpenAI API reference - Chat Completions (temperature, top_p) · OpenAI
Textbooks
- Jurafsky & Martin, Speech and Language Processing (3rd ed. draft), chapter on large language models (temperature sampling)
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Check yourself
Loading…