๐Ÿงฎ Brain Teaser

The Blessing of Normalization: Why Softmax Probabilities Saturate

You have a KK-class classifier that outputs a score vector z=(z1,z2,โ€ฆ,zK)โˆˆRK\mathbf{z} = (z_1, z_2, \ldots, z_K) \in \mathbb{R}^K. The softmax function converts these to probabilities:

pk=ezkโˆ‘j=1Kezj.p_k = \frac{e^{z_k}}{\sum_{j=1}^{K} e^{z_j}}.

Question: Suppose class 1 is the true class, and you scale all scores by a constant T>0T > 0 (i.e., replace z\mathbf{z} by z/T\mathbf{z}/T). This is called temperature scaling.

  1. What happens to the softmax probabilities as Tโ†’0+T \to 0^+? As Tโ†’โˆžT \to \infty?

  2. Now consider the cross-entropy loss for the true class: L(T)=โˆ’logโกp1(T)=โˆ’logโกez1/Tโˆ‘j=1Kezj/T.\mathcal{L}(T) = -\log p_1(T) = -\log \frac{e^{z_1/T}}{\sum_{j=1}^K e^{z_j/T}}. Show that L(T)โ†’0\mathcal{L}(T) \to 0 as Tโ†’0+T \to 0^+ if and only if z1>zjz_1 > z_j for all jโ‰ 1j \neq 1 (i.e., class 1 has the strictly highest score).

  3. What is limโกTโ†’โˆžL(T)\lim_{T \to \infty} \mathcal{L}(T)? Interpret this.

softmaxcross-entropytemperature scalingcalibrationinformation theory

Answer: Temperature Scaling and Softmax Saturation

Key Idea / Intuition

Temperature scaling is a way of "sharpening" or "flattening" a probability distribution. Low temperature amplifies score differences so the model becomes overconfident (winner-takes-all), while high temperature washes them out toward uniform. The cross-entropy loss thus perfectly detects whether the model "got it right" in raw scores (part 2), and tells us the maximum possible entropy of confusion at high temperature (part 3). This connects the geometric intuition of softmax to the information-theoretic meaning of cross-entropy.


Formal Proof / Solution

Part 1: Limits of the softmax probabilities

Replace zkz_k with zk/Tz_k / T. Then:

pk(T)=ezk/Tโˆ‘j=1Kezj/T.p_k(T) = \frac{e^{z_k/T}}{\sum_{j=1}^K e^{z_j/T}}.

As Tโ†’0+T \to 0^+: Divide numerator and denominator by ezmaxโก/Te^{z_{\max}/T} where zmaxโก=maxโกjzjz_{\max} = \max_j z_j:

pk(T)=e(zkโˆ’zmaxโก)/Tโˆ‘je(zjโˆ’zmaxโก)/T.p_k(T) = \frac{e^{(z_k - z_{\max})/T}}{\sum_{j} e^{(z_j - z_{\max})/T}}.

  • If zk<zmaxโกz_k < z_{\max}: the numerator โ†’0\to 0 since (zkโˆ’zmaxโก)/Tโ†’โˆ’โˆž(z_k - z_{\max})/T \to -\infty.
  • If zk=zmaxโกz_k = z_{\max}: the numerator โ†’1\to 1.

So the probability concentrates equally on all classes achieving the maximum score. If there is a unique maximizer (say class 1), then p1(T)โ†’1p_1(T) \to 1 and all others โ†’0\to 0: winner-takes-all / argmax behavior.

As Tโ†’โˆžT \to \infty: All exponents zk/Tโ†’0z_k/T \to 0, so ezk/Tโ†’1e^{z_k/T} \to 1 for all kk:

pk(T)โ†’1Kforย allย k.p_k(T) \to \frac{1}{K} \quad \text{for all } k.

The distribution flattens to uniform โ€” the model becomes maximally uncertain.


Part 2: L(T)โ†’0\mathcal{L}(T) \to 0 iff class 1 has strictly highest score

The loss is:

L(T)=โˆ’logโกp1(T)=logโกโ€‰โฃ(โˆ‘j=1Kezj/T)โˆ’z1T.\mathcal{L}(T) = -\log p_1(T) = \log\!\left(\sum_{j=1}^K e^{z_j/T}\right) - \frac{z_1}{T}.

Divide inside the log by ez1/Te^{z_1/T}:

L(T)=logโกโ€‰โฃ(โˆ‘j=1Ke(zjโˆ’z1)/T).\mathcal{L}(T) = \log\!\left(\sum_{j=1}^K e^{(z_j - z_1)/T}\right).

Note the j=1j=1 term contributes exactly e0=1e^0 = 1 to the sum.

(โ‡’\Rightarrow direction): Suppose z1>zjz_1 > z_j for all jโ‰ 1j \neq 1. Then (zjโˆ’z1)<0(z_j - z_1) < 0 for all jโ‰ 1j \neq 1, so:

e(zjโˆ’z1)/Tโ†’0asย Tโ†’0+.e^{(z_j - z_1)/T} \to 0 \quad \text{as } T \to 0^+.

The entire sum โ†’1\to 1, so:

L(T)=logโก(1+smallย positive)โ†’logโก1=0.โœ“\mathcal{L}(T) = \log(1 + \text{small positive}) \to \log 1 = 0. \checkmark

(โ‡\Leftarrow direction): Suppose some jโˆ—โ‰ 1j^* \neq 1 satisfies zjโˆ—โ‰ฅz1z_{j^*} \geq z_1. Then (zjโˆ—โˆ’z1)/Tโ‰ฅ0(z_{j^*} - z_1)/T \geq 0 and since Tโ†’0+T \to 0^+, this term is at least 1 and does not vanish. The sum inside the log is โ‰ฅ1+1=2\geq 1 + 1 = 2, so:

L(T)โ‰ฅlogโก2>0.\mathcal{L}(T) \geq \log 2 > 0.

Hence L(T)โ†’ฬธ0\mathcal{L}(T) \not\to 0. โœ“\checkmark

Conclusion: L(T)โ†’0\mathcal{L}(T) \to 0 as Tโ†’0+T \to 0^+ if and only if z1=argโกmaxโกjzjz_1 = \arg\max_j z_j strictly.


Part 3: The high-temperature limit of the loss

From Part 1, as Tโ†’โˆžT \to \infty, all pkโ†’1/Kp_k \to 1/K. Therefore:

L(T)=โˆ’logโกp1(T)โ†’โˆ’logโก1K=logโกK.\mathcal{L}(T) = -\log p_1(T) \to -\log \frac{1}{K} = \log K.

Interpretation: logโกK\log K is the entropy of the uniform distribution over KK classes. At infinite temperature, the model is completely ignorant โ€” it assigns equal probability to all classes โ€” and pays the maximum possible cross-entropy loss of logโกK\log K. This is also the cross-entropy of any distribution against the uniform distribution when the truth is known.

In terms of temperature scaling for calibration (a practical ML technique): using T>1T > 1 makes a model less confident and better calibrated when the raw logits are overconfident; the penalty is a higher but bounded loss approaching logโกK\log K.


Summary Table

| Temperature | Probabilities | Cross-entropy loss | |---|---|---| | Tโ†’0+T \to 0^+ (if z1z_1 largest) | p1โ†’1p_1 \to 1, rest โ†’0\to 0 | Lโ†’0\mathcal{L} \to 0 | | Tโ†’0+T \to 0^+ (if z1z_1 not largest) | Mass on argโกmaxโก\arg\max classes | Lโ‰ฅlogโก2>0\mathcal{L} \geq \log 2 > 0 | | T=1T = 1 | Standard softmax | L=โˆ’logโกp1\mathcal{L} = -\log p_1 | | Tโ†’โˆžT \to \infty | Uniform (1/K1/K each) | Lโ†’logโกK\mathcal{L} \to \log K |

Source: The Elements of Statistical Learning, Hastie-Tibshirani-Friedman (2nd ed.); widely known ML folklore

Type: ML/StatsSource: The Elements of Statistical Learning, Hastie-Tibshirani-Friedman (2nd ed.); widely known ML folkloreEdit on GitHub โ†—