Cross-entropy is a loss function that measures how far the probability distribution output by a model is from the target distribution . It is the most widely used loss for training classifiers.
Here, is the number of classes, is the probability the model assigns to class , and is the target distribution. log is the natural logarithm. When the target is a single class (one-hot, with and all others 0), only the term for the correct class remains in the sum, so it simplifies to:
In other words, the higher the probability assigned to the correct class, the smaller the loss, and the lower it is, the more sharply the loss grows. Concrete values are as follows.
| Probability of the correct class | 0.99 | 0.9 | 0.5 | 0.1 | 0.01 |
|---|---|---|---|---|---|
| Loss | 0.01 | 0.11 | 0.69 | 2.30 | 4.61 |
Raising 0.9 to 0.99 reduces the loss by only 0.1, but dropping 0.1 to 0.01 increases the loss by 2.3. A defining feature of cross-entropy is that it penalizes confident wrong predictions most heavily.
The name comes from information theory. It is the average "surprise" experienced by someone who believes in distribution when observing data generated from distribution , and it is minimized when matches . Cross-entropy is the sum of the entropy of itself and the KL divergence, and since the target distribution does not change during training, minimizing cross-entropy is equivalent to minimizing the KL divergence. It also equals the negative logarithm of the probability (likelihood) of the correct labels (the negative log-likelihood), so training with cross-entropy is equivalent to maximum likelihood estimation.

