How does the temperature parameter reshape the sampling distribution?
Temperature divides the logits before softmax; `T<1` sharpens toward the top token, `T>1` flattens toward the tail, `T=0` is greedy argmax.
Imagine the model's raw output as a row of heights, one per possible next word. The highest height is the model's favorite token. Temperature is a knob that scales those heights before they get turned into probabilities. Turn the knob below 1 and the gaps between heights grow, so the favorite towers over everyone else and almost always wins; the output gets predictable, sometimes repetitive. Turn it above 1 and the gaps shrink, so unlikely tokens get a real chance and the output gets more diverse, sometimes off the rails. Set it to 1 and nothing changes; you sample from the trained distribution as-is. Set it to 0 and you skip sampling entirely, just pick the tallest, every time.
Detailed answer & concept explanation~6 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.
5 min: write the formula `p = softmax(logits / T)`, explain low / equal to one / high regimes, describe the T = 0 special case (greedy argmax), state that the effect is non-linear because softmax is non-linear, and give a typical default plus one production pin-low use case.
Real products, models, and research that use this idea.
- OpenAI's Chat Completions API accepts `temperature` from 0.0 to 2.0 and defaults to 1.0; code-gen and structured-output use cases commonly set 0.0 to 0.2.
- Anthropic's Messages API takes `temperature` from 0.0 to 1.0 with a default near 1.0, and tool-use prompts often pin it to 0 for deterministic argument selection.
- vLLM, TGI, and SGLang all expose temperature as a sampling parameter that runs before `top_p` / `top_k` truncation in the engine.
- Hugging Face Transformers' `generate()` exposes `do_sample=False` as an explicit greedy path that bypasses temperature entirely, equivalent to `T = 0` at the API level.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does temperature 0 not guarantee deterministic output on a GPU?
QHow does temperature interact with `top_p` truncation?
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.
Describing temperature as scaling probabilities directly. It scales logits before softmax, which is non-linear in token probability and far more aggressive than a linear rescale.
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.