Contents
07Why training minimizes cross-entropy
7.1Cross-entropy, KL and maximum likelihood
Training data x_1,\dots,x_N define the empirical distribution \hat p, which puts probability 1/N on each example. The average log loss of a model q_\theta on the data is exactly a cross-entropy, and by (5)
The left side is the average negative log-likelihood. H(\hat p) does not depend on \theta, so
minimizing cross-entropy, minimizing forward KL to the data, and maximum likelihood are the same thing (Murphy, 2022, §4.2.2, §6.2.5), (Goodfellow et al., 2016, §5.5). For a classifier, q_\theta is the predicted distribution of the label given the input, and the same argument applies to each conditional distribution.
The two losses have the same gradient but not the same value: cross-entropy cannot go below the entropy of the data, while KL can reach zero. As the newcomer watches the sky and updates his expectations, his KL shrinks and his average surprise falls toward 0.99 bits, never below. A model’s training loss behaves the same way. If its held-out cross-entropy levels off, the remaining loss may be the data’s own unpredictability rather than a flaw of the model.
Worked example 4 (Scoring weather apps). On a rainy day, apps that forecast 90\%, 70\%, 50\%, 10\% and 1\% rain pay 0.15, 0.51, 1.00, 3.32 and 6.64 bits. Averaged over many days, the app that forecasts the true chance pays least, because of the information inequality; the log loss is a proper scoring rule (Good, 1952) (episode 7).
7.2Perplexity
Language models report perplexity, 2^{H_{\mathrm{ce}}} when the cross-entropy is in bits (equivalently e^{H_{\mathrm{ce}}} in nats). A perplexity of K means the model is as unsure as if it were choosing uniformly among K options (Murphy, 2022, §6.1.5). Miami’s forecast has perplexity 2^{0.99}=1.99, about two options; Cupertino’s 2^{0.031}=1.02. GPT-2 (Radford et al., 2019), reading a sentence from Shannon (1951)’s experiment, averages 6.66 bits per token, a perplexity of 2^{6.66}=101 words. In nats the same model scores 4.62 nats per token, and e^{4.62}=101: perplexity does not depend on the unit.
Pause and think. Your classifier’s training cross-entropy keeps falling toward 0, but its validation cross-entropy stops at 0.5 nats and then rises. What is happening?
Show the answer
The model is overfitting. On the training set it can drive the loss toward zero by memorizing labels, but on new data it is surprised by examples it is now overconfident about. The validation curve, not the training curve, estimates H_{\mathrm{ce}} on the true distribution; stop training (or regularize) where it is lowest.