Zenaique

Flashcard: what does the temperature parameter do during LLM generation and how should you set it?

Flashcard·Easy·4.0 · 0·~30s·Asked atPolyaiRobust IntelligenceVernacular Ai·Relevant atAnthropic
Attempt it
TL;DR

Temperature scales the next-token logits before softmax; low T sharpens toward the most likely tokens (deterministic), high T flattens the distribution (diverse), and T = 0 forces greedy decoding.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine the model has a big spinner with one slot per possible next word, and the slot sizes are proportional to how likely each word is. Temperature is a knob that warps the spinner. Turning the knob down (low temperature) makes the most likely slot huge and the rest tiny: the spinner almost always lands on the obvious word. Turning the knob up (high temperature) flattens the slots so even unusual words have a real chance of being picked. Turn it all the way to zero and the spinner stops spinning; you just pick the biggest slot every time. Choose low temperature when you want safe, predictable answers like extracting a fact; choose higher temperature when you want creative variety like brainstorming.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Temperature is the first decoding parameter most people meet and the one that gets misunderstood most often. The casual mental model ('higher equals more creative, lower equals more focused') is correct as far as it goes, but it does not tell you what the knob is actually doing inside the model, how it interacts with the other decoding parameters in a real stack, or where its limits sit.

The right mental model is concrete and mechanical. The model produces a logit (a real-valued score) for every possible next token; temperature scales those logits before the softmax that turns them into a probability distribution; a token is then sampled from the resulting distribution. Different temperatures shape the distribution differently, and that shape is what makes the output more focused or more diverse.

This deep dive walks through the math, the operational mapping from T values to task types, the interaction with top-p and top-k, and the caveats around T = 0 that surprise people the first time they need byte-deterministic replay in production.

The mechanics: what temperature does to the logits

At every generation step the model produces a logit vector z of size equal to the vocabulary (50k-200k tokens depending on tokenizer). To convert logits into a probability distribution, the model applies softmax. With temperature, softmax becomes:

pi=ezi/Tjezj/Tp_i = \frac{e^{z_i / T}}{\sum_j e^{z_j / T}}

When T is small (close to 0), z_i / T becomes large in magnitude. The exponentials in the numerator and denominator stretch the gaps between high-scoring and low-scoring tokens, so the highest-scoring token captures almost all the probability mass and lower-scoring tokens get crushed toward zero. In the limit T -> 0, all the probability lands on the argmax token; this is greedy decoding.

When T is large (above 1), z_i / T shrinks in magnitude. The exponentials compress the gaps, so the distribution flattens. Lower-scoring tokens get a meaningful share of the probability mass, which means they have a real chance of being sampled. In the limit T -> infinity, the distribution approaches uniform over the vocabulary.

The sampling step then draws one token from the (possibly reshaped) distribution. Temperature does not affect what the model knows or what scores it produces; it only affects how those scores translate into a sampling distribution. This is why temperature is a decoding parameter, not a model parameter.

The mapping: which T value for which task
How temperature composes with top-p and top-k
The determinism caveat at T = 0
Temperature in self-consistency and ensemble patterns
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

Real products, models, and research that use this idea.

  • OpenAI's Chat Completions API exposes a temperature parameter 0-2 plus a separate seed parameter; GPT-5.5 in JSON-mode tasks typically runs at temperature 0 or 0.2 for predictable structured output.
  • Anthropic's Messages API for Claude Opus 4.7 accepts temperature 0-1, with prompt-engineering guides recommending 0 for extraction and 0.7-1.0 for creative writing.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow does temperature interact with top-p (nucleus) sampling?
A

Temperature scales the distribution; top-p truncates it to the smallest set whose cumulative probability exceeds p. They are usually applied together: temperature first, then top-p truncation, then sample.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Setting temperature to 0 and assuming the model is now fully deterministic across runs. Other sources of variance (sampling implementation, distributed inference, ties in logits) can still produce different outputs on identical inputs.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Write the softmax formula with temperature; explain what T = 0 and T > 1 do

  • Map T values to task types (extraction vs creative vs assistant)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Spot the error in this explanation of temperature.
Spot the error·Easy