Temperature and Randomness: The Setting That Changes How an AI Writes
What the temperature setting does to a language model's word choices, when to turn it up or down and what it cannot fix.
Key takeaways
- A language model gives scores to many possible next tokens, and software then selects one of them.
- Lower temperature concentrates the choice on the top options, while higher temperature spreads it out.
- Low settings suit extraction and consistent formats, and moderate or higher settings suit brainstorming.
- Temperature cannot repair missing knowledge, and even a very low setting does not guarantee identical or correct answers.
Temperature is a setting that controls how adventurous a language model is when it picks its next piece of text. A low temperature makes it stick closely to the most likely choices, so the writing is more predictable. A high temperature gives less likely choices a better chance, so the writing is more varied and also more likely to wander.
It does not make the model smarter, better informed or more honest. It changes how the model chooses among options it has already scored.
Where the randomness comes in
A language model writes one token at a time. A token is a word or a fragment of a word. At each step, the model produces a probability for each possible next token, based on everything in the text so far.
Software then has to pick. It could always take the single most probable token, a method called greedy selection. Or it could draw one at random, with likelier tokens drawn more often, which is called sampling. Most chat products use some form of sampling, which is a main reason the same question can get different answers.
Because each chosen token becomes part of the input for the next step, one small difference early on can send two replies in quite different directions. The step-by-step process is shown in how a model builds a sentence.
A worked example
Say the text so far is "The morning sky was" and, to keep the arithmetic small, only four continuations are possible. At the default setting of 1, suppose the model gives these probabilities: blue 60 percent, gray 25 percent, clear 10 percent and purple 5 percent.
Changing temperature reshapes these numbers. In effect, each probability is raised to the power 1 divided by the temperature, and the results are rescaled so they total 100 percent.
At temperature 0.5, each value is squared:
0.60² = 0.36 0.25² = 0.0625 0.10² = 0.01 0.05² = 0.0025
Total = 0.435, so divide each by 0.435
blue ≈ 83% gray ≈ 14% clear ≈ 2% purple ≈ 1%
At temperature 2, each value is replaced by its square root:
√0.60 ≈ 0.775 √0.25 = 0.500 √0.10 ≈ 0.316 √0.05 ≈ 0.224
Total ≈ 1.814, so divide each by 1.814
blue ≈ 43% gray ≈ 28% clear ≈ 17% purple ≈ 12% Made-up probabilities for four possible next words. Hypothetical example: the numbers are made up to show the method, not a quote or an average.
The ranking never changes: blue stays on top throughout. What changes is how often the others get a turn.
What low and high settings feel like
At low temperature, replies tend to be plain, consistent and similar from one run to the next. That is welcome when you want the same date format every time or a faithful extraction of names from a form. It can also produce flat prose and, in some cases, repetitive loops.
At high temperature, you see more unusual word choices and more variety between attempts. This can help when you want twenty different names for a community garden. Push it far enough and sentences lose the thread, facts get garbled and the output may turn into nonsense, because very unlikely tokens are being chosen regularly.
The scale is not standard everywhere. Different services allow different ranges and use different defaults, so a number that feels mild in one tool may behave differently in another. Check the provider's documentation instead of carrying numbers across.
Choosing a setting for the job
| Task | Sensible starting point | Why |
|---|---|---|
| Pulling figures from a document | Low | Variation only adds risk |
| Sorting messages into categories | Low | You want consistency |
| Drafting an ordinary email | Moderate or default | Natural phrasing without surprises |
| Brainstorming slogans | Higher | You want range and will filter |
| Writing a poem with several takes | Moderate to higher | Freshness matters more than sameness |
Treat these as starting points. Run the same prompt several times at a setting and look at the spread. If every result is nearly identical and you wanted options, raise it. If replies drift off the instructions, lower it.
There is another route to variety that works at any setting: ask for it. "Give me eight options that differ in tone, and label each tone" often does more than a hotter dial.
Related settings you may meet
Developer tools sometimes expose other controls next to temperature.
- Top-p, also called nucleus sampling, keeps only the most probable tokens whose combined probability reaches a chosen share, then samples among them. In the example above, a top-p of 0.8 would keep blue and gray, which together reach 85 percent.
- Top-k keeps only a fixed number of the most probable tokens.
- Maximum length caps how many tokens the reply may use. It cuts text off and does not make the model plan a shorter answer by itself.
- Seed is a starting value for the random choices that, where offered, helps make runs more repeatable.
Changing several at once makes results hard to interpret, so adjust one and observe. Exact behavior depends on the service.
What temperature cannot do
It is tempting to think a temperature of zero means "facts only". It does not. If the most probable continuation is wrong, a low setting will deliver that wrong answer reliably. Invented details come from the model producing plausible text without solid support, as explained in why chatbots invent facts. Lower randomness may reduce some stray errors, but checking against a source is still needed.
Nor does a low setting promise word-for-word repetition. Small numerical differences in how hardware performs calculations, changes to the model behind the service, retrieved documents that differ and hidden instructions can all alter results.
High temperature, for its part, is not imagination. It increases variety in the choice of tokens. Whether the result is good still depends on the prompt, the model and your judgment.
Why not always take the most likely word?
If one choice is the most probable, it seems sensible to take it every time. For short factual or formatting tasks, that is often reasonable.
Longer writing is different. Always taking the top option can lead a model into circles, where a phrase makes the same phrase likely again. It also tends to produce the safest, most generic wording. Human writing regularly uses words that were not the single most predictable ones, and a little sampling lets the model do the same.
There is also a limit to greed as a strategy. The best next token is not necessarily the start of the best whole sentence. Choosing step by step, the model commits to each piece before seeing what it will lead to.
Sampling has the opposite hazard. Across hundreds of steps, even a small chance of an odd choice will occasionally come up. Once a strange or wrong token is on the page, the model treats it as part of the text and builds on it. That is one way a reply that began well can drift. Filters such as top-p reduce the risk by removing the long tail of very unlikely options before the draw.
A small experiment to try
If you have access to a tool with a temperature control, spend a quarter of an hour on this.
- Write one prompt that invites variety, such as "Name a new café on a quiet street." Run it five times at a low setting and record the results.
- Run it five times at the default and five times at a higher setting.
- Write one prompt with a single right answer, such as extracting the total from an invented receipt, and repeat the same three settings.
- Compare. Count how many replies were distinct, how many followed instructions and how many contained errors.
For the naming task you will probably see repeats at the low end and more spread higher up. For the receipt, variety has no value, and any difference between runs deserves a look.
Fifteen runs cannot establish a rule. They can show you how a particular tool behaves on your kind of work, which is more useful than a general recommendation. Repeat the test if the provider changes the underlying model, since a setting that suited the old one may not suit the new.
If you cannot find the dial
Many consumer chat apps do not show a temperature control. The provider chooses it, sometimes differently for different modes. Some models, including certain ones designed to work through problems before answering, restrict or fix the setting. Developer interfaces more often expose it. These details change, so look at the current documentation.
Without a dial, you can still steer toward the effect you want:
- For consistency, give a strict format and one filled-in example.
- For fidelity, supply the source text and ask the model to use only that.
- For variety, request several distinct options, or start fresh conversations.
- For checking, run an important question twice and investigate any disagreement.
Agreement between two runs does not prove correctness, since both may share the same mistake. A five-minute fact check is the better safeguard.
Common questions
Is a temperature of zero fully deterministic?
It usually means choosing the top token each time, which makes output far more repeatable. In hosted services, small differences can still appear.
Does higher temperature cost more?
The setting itself typically does not change the price per token. A rambling reply that runs longer can use more tokens, and discarded attempts add up.
Why is it called temperature?
The term comes from physics, where higher temperature means particles are spread more widely across possible states. The mathematics of reshaping the probabilities is closely related.