T > 1 flattens the distribution: gaps between scores shrink, attention spreads across more positions. In the limit T -> infinity the row becomes uniform.
Imagine a vote where everyone shouts a number out of 100 for each candidate. If you shrink everyone's volume to a whisper, the loudest shouter no longer drowns out the others and the final vote spreads out instead of going to a single landslide winner. Dividing the model's raw scores by a temperature greater than 1 is exactly that volume knob: it shrinks every number toward zero, so the final share of attention across all the items in the row evens out instead of being captured by one peak. Turn the knob the other way and the loudest voice wins everything.
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.
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 T in softmax controls how peaked or flat the output distribution is. Dividing scores by T > 1 shrinks them toward zero, narrows the ratios between exponentials, and produces a flatter post-softmax distribution. The two limits are interpretable: T -> infinity gives a uniform distribution (maximum entropy), and T -> 0 gives a one-hot argmax (minimum entropy). For any finite T > 1, the distribution sits monotonically between the two extremes.
This deep dive walks the temperature-softmax formula and its limits, distinguishes shift-invariance from scale-non-invariance, explains the sqrt(d_k) divisor as a built-in attention temperature, and traces where temperature manipulation actually shows up in production (LLM output sampling, knowledge distillation, not per-layer attention).
Mental model: temperature is a one-parameter family interpolating between argmax and uniform. The sqrt(d_k) scaling in attention is a fixed temperature; the LLM's output temperature is the tunable knob you actually adjust at decoding.
The temperature-softmax formula and its limits
Softmax with temperature T applies the formula:
The two limits
- T -> infinity: every
s_j / T -> 0, everye^{0} = 1, the denominator isT_k, so every entry is1/T_k. The row is uniform. Maximum entropylog(T_k). - T -> 0+: gaps between scores explode (
(s_j - s_max) / T -> -infinityfor all non-max j), so non-max exponentials vanish and only the max survives. The row is one-hot atargmax_j s_j. Minimum entropy0.
The intermediate regime
For any finite T > 1, the distribution is monotonically softer than T = 1: the ranking of entries is preserved, but the relative magnitudes are compressed. The entropy H(w(T)) is a monotonically increasing function of T.
For any finite T < 1, the distribution is monotonically sharper than T = 1: ranking preserved, magnitudes amplified, one entry dominates more aggressively.
The display form
Key insight: temperature is not a binary switch. It is a smooth interpolation parameter between the two extremes, with the entropy of the distribution as a monotone function of T.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Vaswani et al. 2017: section 3.2.1 explains the sqrt(d_k) divisor as a built-in temperature chosen to keep pre-softmax variance near 1.
- LLM sampling at inference time: T = 0.7 (slightly sharper than default) is a common chat-model setting; T > 1 produces more diverse text; T -> 0 approaches greedy decoding.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy is softmax shift-invariant but not scale-invariant, and what is the practical implication?
Shift invariance: softmax(x + c) = softmax(x) because the additive constant cancels from numerator and denominator (e^{x_i + c} = e^{x_i} e^c). The e^c factor is the same in every entry, so it drops out. Scale non-invariance: softmax(x / T) != softmax(x) because dividing by T scales the gap between any two inputs by 1/T, and the exponential function is non-linear in ratios. Practical implication: the row-max stabilization trick softmax(x - max(x)) is mathematically free (shift-invariant), so production code uses it everywhere. Temperature scaling, on the other hand, genuinely reshapes the distribution.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Claiming softmax is scale-invariant. It is shift-invariant (subtract a constant from every input and weights are unchanged), not scale-invariant; dividing by T > 1 reshapes the distribution.
60 second bullets to scan on the way to the call.
The temperature-softmax formula softmax(x / T)
Behavior at T > 1 (flatter), T < 1 (sharper), T -> infinity (uniform), T -> 0 (argmax)
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.