Explainer
What does temperature mean in AI?
How does an LLM choose the next word?
A large language model (LLM) writes one token at a time. A token is a small chunk of text, often a word or part of a word. At each step the model scores every token in its vocabulary and turns those scores into probabilities.
Suppose the text so far is “The sky is.” The model might give “blue” a 70% chance, “clear” 15%, “falling” 1%, and thousands of other tokens tiny chances. The app then has to pick one. Always choosing the top option is called greedy decoding. Picking at random, weighted by the probabilities, is called sampling.
Sampling is why you can ask the same question twice and get two different answers. Temperature is the main dial that controls how adventurous that sampling is.
What does temperature actually do?
Temperature reshapes the probabilities before a token is picked. A low temperature sharpens them: the favorite gets even more likely and long-shot options nearly vanish. A high temperature flattens them: the favorite loses some of its lead and unusual words get a real chance.
In the example above, at a low temperature “blue” might rise from 70% to over 95%. At a high temperature it might fall to 40%, while “clear,” “grey” and stranger options share the rest.
At or near zero, the model behaves almost like greedy decoding and nearly always picks its single top choice. Push temperature too high and text can drift off topic or become incoherent, because many low-quality tokens start getting chosen.
Low vs high temperature: what is the difference in practice?
Low temperature gives consistent, conservative output. It suits tasks with one right answer: extracting data, classifying text, answering factual questions, writing code, and producing structured formats like JSON.
High temperature gives variety. It suits brainstorming, fiction, marketing taglines, and anything where you want several different options rather than the single safest phrasing.
Temperature does not make a model smarter or more knowledgeable. A low setting will repeat a wrong belief consistently; a high setting will not unlock hidden creativity, it just samples more widely from what the model already knows.
What is top-p, and how is it different from temperature?
Top-p, also called nucleus sampling, limits which tokens are eligible at all. With top-p set to 0.9, the model ranks tokens by probability and keeps only the smallest group whose probabilities add up to 90%. It then samples from that group and ignores the long tail.
The method was introduced by Ari Holtzman and colleagues in a 2019 paper that showed it produced more natural long-form text than earlier methods. A related setting, top-k, keeps a fixed number of top tokens, such as the 50 most likely.
Temperature changes how probability is spread; top-p and top-k cut off unlikely options. Most providers suggest adjusting one or the other, not both at once, because their effects interact in ways that are hard to predict.
What temperature should you use?
Ranges differ by provider, so check the documentation. Anthropic’s API accepts 0 to 1 with a default of 1. OpenAI’s classic APIs accept 0 to 2, where 1 is the default and values above about 1.5 tend to produce noticeably erratic text.
As a starting point, use 0 to 0.3 for factual, analytical and coding work, around 0.5 to 0.7 for general writing and conversation, and 0.8 to 1 (or slightly higher where allowed) for brainstorming and creative work. Then test on real examples, because the best value depends on the model and the task.
Some reasoning models restrict or ignore sampling settings. Several OpenAI reasoning models, for example, reject custom temperature or top-p values in certain modes. If a setting is rejected, the provider has chosen a fixed sampling strategy for that model.
Why isn’t temperature 0 perfectly deterministic?
You might expect temperature 0 to give identical answers every time. In practice it usually gives very similar answers, not guaranteed identical ones. Anthropic’s API documentation states that results will not be fully deterministic even at 0.
The main reasons are in the serving infrastructure. Models run on GPUs that process many users’ requests together in batches, and the batch size changes with traffic. Tiny differences in how numbers are added up in different batch configurations can change a score in the last decimal place. When two candidate tokens are nearly tied, that small difference can flip the choice, and every later token then follows a different path.
Model updates, different hardware and changes to hidden system prompts can also alter outputs over time. If you need repeatable results, store the outputs you rely on rather than expecting to regenerate them exactly.
Can you change temperature in ChatGPT, Claude or Gemini apps?
Usually not directly. Consumer chat apps pick sampling settings for you and generally do not expose a temperature slider. Developer tools do: API playgrounds, the APIs themselves and many third-party apps built on them let you set temperature and top-p per request.
In a chat app, you can get a similar effect with instructions. Ask for “the single most likely answer, no speculation” for focus, or “ten wildly different options” for variety.
Suggested starting temperatures by task (adjust after testing)
| Task | Suggested temperature | Why |
|---|---|---|
| Data extraction, classification, JSON output | 0 – 0.2 | One correct answer; consistency matters most |
| Code generation and debugging | 0 – 0.3 | Small random changes can break code |
| Factual Q&A and summaries | 0 – 0.3 | Reduces drift away from the source |
| Customer support replies | 0.3 – 0.5 | Accurate but not robotic |
| General writing and chat | 0.5 – 0.8 | Natural variety without losing focus |
| Brainstorming, fiction, slogans | 0.8 – 1.0+ | Variety is the goal; review output carefully |
Examples
- An invoice-parsing script runs at temperature 0 so the same PDF produces the same extracted fields on each run.
- A copywriter asks for 20 headline ideas at temperature 1.0 and gets a wider spread than at 0.3, then picks the best three.
- At top-p 0.9, if the top five tokens cover 90% of the probability, only those five can be chosen and the other thousands are ignored.
- Two runs of the same prompt at temperature 0 produce identical first paragraphs but differ in one word in paragraph three, after which the wording diverges.
- A support bot set to 0.4 gives accurate policy answers while varying its phrasing so replies do not feel copy-pasted.
Common questions
Does a higher temperature cause more hallucinations?
It can. Higher temperature makes less likely tokens more probable, and some of those lead to unsupported or wrong statements. Lowering temperature helps for factual work, but it does not fix errors the model is already confident about. Grounding in real sources and verification matter more.
Why is it called temperature?
The name comes from physics and statistics, where temperature in a probability formula controls how evenly energy or probability is spread. In a language model, the scores for each token are divided by the temperature value before being turned into probabilities, which is the same mathematical role.
Should I change temperature and top-p at the same time?
Generally no. Both control randomness, and combining them makes results harder to predict and tune. Pick one, usually temperature, leave the other at its default, and adjust in small steps while testing on real examples of your task.
Is temperature 0 the same as greedy decoding?
Conceptually, yes: at 0 the model should always take its top-scoring token. Real systems may treat 0 as a very small positive value, and serving-level numerical differences can still change near-tied choices, so outputs are near-deterministic rather than perfectly identical.
What is a good default temperature for a chatbot?
Many teams start around 0.5 to 0.7 for open conversation, and lower, around 0.2 to 0.4, for support or knowledge-base bots that must stay accurate. The provider’s default is also a reasonable starting point. Test with real user questions before settling on a value.
Sources and further reading
Glossary terms
- LLM
An LLM (large language model) is an AI model trained on huge amounts of text to predict the next piece of text in a sequence. That one skill lets it answer questions, write, summarise, translate and code. ChatGPT, Claude and Gemini are apps built on LLMs.
- Token
In AI, a token is the small unit of text a language model reads and writes. A token can be a whole word, part of a word, a punctuation mark or a space. In English, one token averages about four characters, or roughly three-quarters of a word.
- Hallucination
An AI hallucination is when a language model produces information that sounds confident and plausible but is false, invented or unsupported by its sources, such as a fake citation, a wrong date or a quote nobody said. The model is not lying; it is generating likely-sounding text.
Keep reading
- What is an LLM?
An LLM (large language model) is an AI system trained on huge amounts of text to predict the next piece of a sentence. By doing that prediction billions of times, it learns grammar, facts, and patterns of reasoning well enough to answer questions, write, summarize, translate, and generate code. Chatbots like ChatGPT and Claude are built on LLMs.
- What are tokens in AI?
Tokens are the small chunks of text that AI language models read and write, usually a whole short word, part of a longer word, or a punctuation mark. In English, one token averages about four characters or three-quarters of a word. Tokens matter because AI pricing, speed, and context-window limits are all measured in them.
- What is an AI hallucination?
An AI hallucination is when a language model states something false or unsupported as if it were true, such as an invented fact, a fake citation or a quote nobody said. It happens because models generate plausible-sounding text rather than looking facts up. Grounding answers in real sources and verifying important claims are the main defenses.
- What is a system prompt?
A system prompt is a set of instructions given to an AI model before the conversation starts, telling it who it is, what it should do and how it should behave. Users usually never see it. It sets the role, tone, rules and background knowledge, while user prompts are the individual questions or requests that follow.
- Prompt vs context engineering
Prompt engineering is the craft of wording instructions so a model understands the task. Context engineering is the wider job of deciding everything the model sees on each call: system prompt, retrieved documents, tool definitions and results, memory, examples, and conversation history, all within a limited context window. Prompt engineering is one part of context engineering.