Skip to main content

AI glossary Models & Architecture

What is temperature in an LLM?

← All glossary terms
In short

A sampling parameter that controls how random a language model's choice of the next token is: low is focused, high is varied.

Explained

Temperature is a parameter applied when a language model generates text, controlling how much randomness goes into choosing each next token. The model assigns a probability to every possible next token; temperature reshapes that distribution before a token is sampled. A low temperature concentrates the choice on the most likely tokens and gives focused, repeatable answers; a higher temperature spreads it out and gives more varied, creative and less predictable text. Choosing it is part of matching a model to the task, from factual extraction to brainstorming.

How it works

At each step the model produces a score for every token in its vocabulary. These scores are divided by the temperature and turned into probabilities. Dividing by a small number exaggerates the differences, so the top tokens dominate; dividing by a larger number flattens them, so less likely tokens get more of a chance.

At or near zero, generation becomes close to always picking the most likely token. Even then, outputs are not guaranteed to be identical across calls, because of how models are served.

Which value for which task

  • Low values suit extraction, classification, structured output, code and answers that must stay close to the sources.
  • Middle values suit general assistance and writing where some variation is welcome.
  • Higher values suit brainstorming, naming and creative drafts, where variety matters more than consistency.
  • Whatever the setting, test it: the effect differs between models, and the provider's default is often a reasonable start.

Temperature, top-p and top-k

Temperature changes the shape of the whole probability distribution. Top-k keeps only the k most likely tokens. Top-p, or nucleus sampling, keeps the smallest set of tokens whose probabilities add up to p, cutting off the unreliable tail.

They can be combined, but changing several at once makes behaviour hard to reason about; providers usually recommend adjusting one. Some providers have also stopped accepting custom sampling values on their newest models and recommend steering behaviour through the prompt instead, so check the documentation of the model you use.

Frequently asked questions

What does temperature 0 mean?

It means the model almost always picks the most likely next token, giving the most focused and repeatable output. It does not guarantee identical answers on every call, and it does not make the answer correct: a model can be confidently wrong at temperature 0.

Does a higher temperature cause more hallucinations?

It can increase them, because less likely tokens are chosen more often, which can lead the text away from the facts. But low temperature does not prevent hallucinations either; grounding answers in sources and evaluating them matter more.

What is the best temperature for an LLM?

There is no single best value. Use low values for factual, structured or repeatable tasks and higher ones for creative work, then test with your own examples. The range and default differ between providers.

What is the difference between temperature and top-p?

Temperature reshapes the probabilities of all candidate tokens. Top-p removes the least likely candidates, keeping only those that together reach a probability threshold, and samples from them. Both control variety, in different ways.

Why can't I set temperature on some models?

Some providers fix sampling parameters on certain models, for example newer ones or those that use extended reasoning, and reject non-default values. In that case, guide the style and consistency of answers through instructions and examples in the prompt.

Where it shows up at Thinkia

Further reading

Sources

Updated: 2026-10-21

Want to see how this applies to your organisation?

Talk to an AI Expert