# Temperature (LLM sampling)

> Canonical: https://skillalmanac.com/glossary/temperature-sampling | Last verified: 2026-11-24 | Index status: index-eligible

In language-model token sampling, temperature adjusts the probability distribution used to select tokens. A lower value concentrates probability on the most likely tokens; a higher value spreads probability more evenly. It affects generation only when the decoding method uses it.

Also called: LLM temperature, temperature AI, temperature setting LLM, temperature parameter, sampling temperature.

## In plain language

An autoregressive text generator predicts the next token according to a probability distribution. When temperature is used for sampling, lowering it concentrates probability on the most likely tokens, while raising it spreads probability more evenly. A decoder that does not use temperature will ignore that setting. IBM notes that temperature is often conflated with creativity, but this is not always the case.

## Technical definition

IBM describes how each token is assigned a logit, and the set of tokens is normalized into a softmax probability distribution. The temperature parameter modifies this distribution. In the OpenAI chat completions reference, temperature is a number between 0 and 2 with a default of 1; higher values like 0.8 make output more random and lower values like 0.2 make it more focused and deterministic. OpenAI generally recommends altering temperature or top_p but not both. In Hugging Face Transformers, GenerationConfig temperature modulates next-token probabilities and defaults to 1.0 if not set. Its temperature warper requires do_sample=True to affect generate. For the standard decoding strategies, num_beams=1 gives greedy decoding with do_sample=False or multinomial sampling with do_sample=True; num_beams>1 gives beam-search decoding or beam-search multinomial sampling respectively.

## How it shows up when you use agents

In the OpenAI chat completions reference, temperature is an optional request parameter. In Hugging Face Transformers, it is a field of GenerationConfig. For the standard strategies, do_sample controls whether to sample: with num_beams=1, False selects greedy decoding and True selects multinomial sampling. With num_beams>1, the corresponding methods are beam-search decoding and beam-search multinomial sampling.

When sampling uses temperature, it changes the probability distribution used to select the next [token](/glossary/token) during [inference](/glossary/inference). Hugging Face's TemperatureLogitsWarper documentation explicitly requires do_sample=True; otherwise temperature has no effect on generate. OpenAI's reference describes [top-p](/glossary/top-p) as an alternative to sampling with temperature, and generally recommends altering one of the two but not both.

## Common confusions

- **Temperature versus top-p.** OpenAI's reference describes top-p as nucleus sampling, an alternative to sampling with temperature, in which the model considers the tokens comprising the top probability mass.
- **Temperature versus creativity.** IBM says temperature is often conflated with creativity, but this is not always the case, and suggests thinking of it as how broadly the model uses text from its training data.
- **Temperature versus focus.** OpenAI's reference says lower values like 0.2 make output more focused and deterministic, and higher values like 0.8 make it more random.

## Worked examples in this catalogue

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: Builds and validates an eval dataset for any LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.

Why it exercises the concept: Prepare the same cases for comparing temperature settings in a separate evaluation harness. This skill checks the dataset; it does not run or score the model.

## Related terms

- [Inference](https://skillalmanac.com/glossary/inference.md)
- [Token](https://skillalmanac.com/glossary/token.md)
- [Top-p sampling](https://skillalmanac.com/glossary/top-p.md)
- [Large language model (LLM)](https://skillalmanac.com/glossary/large-language-model.md)
- [AI hallucination](https://skillalmanac.com/glossary/hallucination.md)
- [Prompt engineering](https://skillalmanac.com/glossary/prompt-engineering.md)
- [Softmax](https://skillalmanac.com/glossary/softmax.md)

## Sources

- [Create chat completion (API reference)](https://developers.openai.com/api/reference/resources/chat/subresources/completions/methods/create), OpenAI (accessed 2026-11-24)
- [Generation (GenerationConfig)](https://huggingface.co/docs/transformers/main_classes/text_generation), Hugging Face (accessed 2026-11-24)
- [TemperatureLogitsWarper — sampling requirement](https://huggingface.co/docs/transformers/internal/generation_utils#transformers.TemperatureLogitsWarper), Hugging Face (accessed 2026-11-25)
- [What is LLM Temperature?](https://www.ibm.com/think/topics/llm-temperature), IBM (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-24. [Glossary index](https://skillalmanac.com/glossary.md).
