Answers · The mathematics underneath
Why can't cross entropy loss go below the entropy of the labels?
In shortCross entropy cannot fall below the uncertainty already in the labels because it is that uncertainty plus a non-negative distance from the model to the labels.
It cannot because cross entropy is exactly the entropy of the label distribution plus a non-negative distance from the labels to the model. The entropy term is fixed by the labels before the model is built, so training can only reduce the distance term to zero, at which point the loss equals the entropy of the labels.
Here is how often outcome actually occurs in the context, and is the probability the model gives it. The identity is obtained by adding and subtracting , which changes nothing. The first term, , contains no at all. The second term, , contains the model and is zero only when the model matches the labels exactly.
The floor is a property of the labels
Take a context with two outcomes and , using natural logarithms. The label entropy is . A perfect model therefore reports a loss of , not zero, and no model can beat it. A model reports , which is above the floor. A model reports , which is above the floor. The loss moves; the floor does not.
| q first outcome | q second outcome | H(q) |
|---|---|---|
| 1 | 0 | 0.000 |
| 0.5 | 0.5 | 0.693 |
| 0.9 | 0.1 | 0.325 |
The natural guess is that a lower loss always means a model closer to perfect, and that a perfect model would report zero. That is true only for one-hot labels. With the entropy is . With the perfect model reports . Reading that as error confuses two different quantities: the uncertainty already in the labels, and the model's distance from them. The distance is the only part that measures the model, and it is zero at .
| step | p on the first outcome | loss | floor | distance above the floor | what happened |
|---|---|---|---|---|---|
| 1 | 0.5 | 0.693 | 0.693 | 0 | Exactly right. The loss equals the floor and the distance term is zero. |
| 2 | 0.7 | 0.78 | 0.693 | 0.087 | A modest overcommitment costs little. |
| 3 | 0.95 | 1.524 | 0.693 | 0.83 | Confident, and now paying for it. |
| 4 | 0.01 | 2.308 | 0.693 | 1.614 | Nearly ruled out something that happens half the time. This is the expensive mistake. |
Why the distance cannot be negative
The second term is a Kullback-Leibler divergence. It is zero when for every outcome, and positive otherwise. That is the statement that makes the floor a floor rather than a coincidence: every model's loss is plus something non-negative.
The divergence is not symmetric. The loss uses , averaging over what actually happens. For and , the distance above the floor is . The reverse divergence is . The version used by the loss punishes a model far more harshly for putting near-zero probability on something that happens than the reverse would. That is why a model trained this way tends to hedge rather than commit.
The floor vanishes when the labels are one-hot. If , then , and the loss is , which tends to zero as . With hard labels, zero is a limit rather than a value attained by a finite model. If the labels are smoothed or genuinely noisy, the floor is positive again. If the model puts probability zero on an outcome with , the loss is infinite, not merely high. The floor is a property of the label distribution and the choice of loss, not of the optimiser.
Worth keeping
- Cross entropy equals the entropy of the labels plus the Kullback-Leibler divergence from the labels to the model, so its minimum over all models is the label entropy.
- A perfect model of a fifty-fifty label distribution still has loss ln 2 = 0.693, not zero.
- The floor disappears only when the label distribution is one-hot, in which case the label entropy is zero.
Where this goes next
This question is one step of The Mathematics of Cross Entropy, a course that works through its subject from the beginning. The page that teaches this part of it is What Minimising It Is Really Doing, and it reads the whole way through whether or not you have an account.
What an account changes is the practice: problems standing under every idea, marked with a reason rather than a tick, in a copy of the course that is yours.
Read that pageThe whole courseOther questions people ask about this
- What does a perplexity of 10 actually mean?A perplexity of 10 means the model's average loss is about 2.30 nats per prediction, equivalent to a uniform choice among ten equally likely options, not a 10 percent accuracy.
- What does temperature scaling actually change in a model's probabilities?It divides every score by one positive number before the softmax, so the probabilities become sharper or flatter while the ranking and top prediction stay the same.
- Why does subtracting the max from the logits not change softmax?Subtracting the largest score is an exact rewriting of softmax, not a change to the distribution: the same factor cancels above and below.
- Why does cross entropy loss only use the probability of the correct class?Because a definite label puts all the target weight on the correct class and none on the others, so every other term is multiplied by zero.
- What is the difference between variance and standard deviation?They measure the same spread: variance is the average squared distance from the mean, standard deviation is its square root, so you report the standard deviation and calculate with the variance.
- How do you make a vague claim precise enough to tell whether it's true?Fix what is being talked about, what is asserted, which cases are covered and the cut-off, then name an observation that would prove it false.