Flashcard: what does the temperature parameter do during LLM generation and how should you set it?
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.
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.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: define temperature as the softmax scaler, write the formula, map T values to tasks, distinguish from top-p, and call out the T = 0 determinism caveat.
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.
- Self-consistency techniques sample 5-20 reasoning chains at temperature 0.7-1.0 and majority-vote the answer; the diversity from temperature is what makes the vote informative.
- vLLM and Ollama expose temperature alongside top-p and top-k as standard decoding parameters; common production defaults are T = 0.7 and top-p = 0.9 for general assistant tasks.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow does temperature interact with top-p (nucleus) sampling?
QWhy might you want non-zero temperature for self-consistency even on a factual task?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.