AI Glossary / Generative AI and language / Intermediate
LLM Temperature
Definition
LLM temperature is a generation setting that rescales a language model's next-token scores before sampling. Lower positive temperatures concentrate probability on higher-scoring tokens; higher temperatures spread probability more broadly. Temperature changes how the system selects from its predicted alternatives. It does not add knowledge, verify facts, or directly measure the creativity or correctness of a complete answer.
What it means
When a model writes, it repeatedly assigns scores to possible next tokens. A token may be a word, part of a word, or punctuation. Several continuations can be plausible at each step. Temperature changes the relative chances of selecting those alternatives when sampling is enabled. A lower setting often makes wording less variable, while a higher setting allows less likely choices more opportunity. The effect depends on the prompt, the model, and other generation controls. The same numerical setting need not produce the same style across different systems.
How it works
In the standard formulation, divide each next-token logit by a positive temperature T, then apply softmax to turn the adjusted scores into probabilities. A logit is an unnormalized score, not a probability. At T = 1, temperature leaves the original softmax distribution unchanged. For T below one, differences between scores become more influential; for T above one, they become less influential. Positive temperature scaling alone preserves the ranking of finite logits. It changes their probabilities, not which score is largest. Subsequent sampling draws a token, and the model then computes a fresh distribution using the extended context. Filters such as top-k or top-p can further restrict the candidates, so the final behavior reflects the whole decoding procedure.
Three practical examples
- A team generating alternative event taglines experiments with temperature to obtain a broader pool, then reviews the suggestions for relevance and originality.
- A developer comparing document-extraction prompts uses a stable decoding configuration so that random variation does not obscure the comparison.
- A teacher asks for several different practice sentences and evaluates whether increased variation still respects vocabulary and difficulty constraints. Temperature can change variety, but the constraints still need to be checked.
Think of it this way
Think of a weighted draw from a bowl containing several possible next steps. Lower temperature makes the already favored options dominate the draw; higher temperature makes the weights more even. The analogy is limited because the bowl is rebuilt after every selected token. Choosing an unusual early token changes the context and therefore the later choices. There is no fixed collection of complete answers whose creativity is directly controlled by one dial.
Worked example
Suppose only three tokens are available and their probabilities at temperature one are 0.6, 0.3, and 0.1. Under standard temperature scaling, the new probabilities are proportional to each original probability raised to the power 1/T. At T = 0.5, square the probabilities: 0.36, 0.09, and 0.01. Their sum is 0.46, so the normalized probabilities are approximately 0.7826, 0.1957, and 0.0217. The most likely token becomes more dominant. At T = 2, take square roots: approximately 0.7746, 0.5477, and 0.3162. After normalization, the probabilities are approximately 0.4727, 0.3343, and 0.1930. The first token is still most likely, but the third now has a greater chance. This calculation assumes no additional filtering or score adjustments. It says nothing about which token would lead to a factually correct sentence.
Illustrative case study
Fictional case: Alder Training produces short practice dialogues. Its editor compares several temperatures using the same lesson prompts and requests multiple samples for each configuration. Higher-temperature samples include more varied situations, but some introduce vocabulary beyond the lesson level. Lower-temperature samples are more repetitive, and a few still contain the same grammatical mistake. The editor chooses a configuration using a rubric for vocabulary, correctness, and useful variation, then adds review checks. The lesson is that variation and quality must be measured separately; neither a high nor a low setting automatically satisfies the teaching goal.
Common misconceptions and mistakes
A frequent mistake is treating temperature zero as ordinary division by zero. Mathematically, the softmax formula requires a positive temperature; approaching zero concentrates mass on the highest score, with ties requiring care. Some products use a zero setting to request greedy behavior, while other implementations reject it. Another mistake is assuming low temperature prevents hallucination. It may repeatedly select the same incorrect continuation. Temperature is also not necessarily active in every decoding mode. For example, an implementation may ignore it when sampling is disabled. Check the actual interface rather than assuming the setting has an effect.
Business use
Choose temperature through task-specific evaluation. For each candidate configuration, compare multiple outputs on representative prompts and record the model version, sampling mode, filters, and length limits. For creative work, count useful alternatives rather than simply counting different strings. For structured extraction, measure field correctness and valid formatting rather than assuming low variability means reliability. If reproducibility matters, record seeds where supported and document the execution environment, while recognizing that software or hardware differences can still affect results. A change in temperature should be treated as a change to the tested system.
People also ask
Does higher temperature always produce better ideas?
No. It changes sampling probabilities and can produce either useful variety or irrelevant continuations.
Does lower temperature change the model's training?
No. It is normally applied during generation to scores produced by an already trained model.
Is a zero setting guaranteed to produce identical outputs forever?
No. Interface behavior, ties, implementation details, and changes to the surrounding system can affect reproducibility.
Check your understanding
If token A has a higher finite logit than token B, can positive temperature scaling alone reverse their ranking?
Answer: No. Dividing both by the same positive number preserves the ranking. Sampling may still select B, and other processing steps may change the final candidate distribution.
Related terms
- Token
- Logit
- Softmax
- Sampling
- Greedy decoding
- Top-k sampling
- nucleus sampling
- random seed
- decoding strategy
Learn next
Recalculate the three-token example at another positive temperature. Then add a top-k filter that retains only two tokens and renormalize. This separates the effect of reshaping probabilities from the effect of removing candidates altogether.
More in Generative AI and language
- Language model - A language model is a model of patterns in language, commonly expressed through probabilities over tokens or token sequences.
- Latent diffusion - Latent diffusion is a generative modeling approach that performs a diffusion process in a learned latent representation instead of directly in the original...
- Latin hypercube sampling - Latin hypercube sampling is a method for selecting combinations of input values so that each input's range is represented evenly through equal-probability...
- LLM-as-a-judge - LLM-as-a-judge is an evaluation method in which a large language model assesses an answer, conversation, or other output using specified criteria.
- LLM evaluations (evals) - LLM evaluations, often shortened to evals, are structured tests used to measure how a large language model or a system built around it performs.
- Machine translation - Machine translation is the automatic conversion of text or speech content from one human language into another by a computer system.
Sources
Hugging Face Transformers, Utilities for generation, TemperatureLogitsWarper: https://huggingface.co/docs/transformers/internal/generation_utils#transformers.TemperatureLogitsWarper Hugging Face Transformers, Text generation: https://huggingface.co/docs/transformers/llm_tutorial
Previous: LLM evaluations (evals) Next: Local beam search