“Cross-entropy loss is a machine learning loss function that measures how closely a model’s predicted probability distribution aligns with the true distribution of the actual labels. Lower values indicate accurate predictions, while confident mistakes are heavily penalised through a logarithmic calculation that pushes the loss sharply upwards.” – Cross-entropy loss – Machine learning

Reliable classification depends on more than selecting the right class. A useful model must also express how strongly the available evidence supports each possible outcome. Cross-entropy loss turns that requirement into a differentiable training objective: it rewards probability assigned to the observed label and penalises probability withheld from it. The penalty is asymmetric in practical effect, because a prediction that is slightly wrong is treated very differently from one that is confidently wrong.

For a target distribution p and a predicted distribution q over the same set of classes, cross-entropy is H(p,q)=-\sum_x p(x)\log q(x). Here, p(x) represents the target probability of outcome x, while q(x) represents the probability assigned by the model. The logarithm measures surprisal: assigning a small probability to an event that occurs creates a large loss. The base of the logarithm determines the unit, with natural logarithms producing nats and logarithms base two producing bits.1,2

In ordinary single-label classification, the target is often one-hot. If the observed class is y, its target probability is one and every other target probability is zero, so the example-level loss becomes L=-\log q(y). A model assigning probability 0,9 to the correct class incurs a relatively small penalty, whereas probability 0,01 produces a much larger one. If the model assigns exactly zero probability to the observed class, the idealised loss tends towards infinity, which explains why confident mistakes dominate the objective.1,2

For a dataset containing n examples, the usual empirical objective is L=-\frac{1}{n}\sum_{i=1}^{n}\log q_{i,y_i}. The parameter values of the model are adjusted to minimise this average. In a binary problem, with label y\in\{0,1\} and predicted probability \hat{y}, the corresponding expression is L=-y\log\hat{y}-(1-y)\log(1-\hat{y}). This is commonly called binary cross-entropy or log loss. For several mutually exclusive classes, a softmax converts logits z_k into probabilities using q_k=\frac{\exp(z_k)}{\sum_j\exp(z_j)}, after which the loss evaluates the probability of the true class.

The information-theoretic interpretation clarifies why this objective is so widespread. Cross-entropy decomposes as H(p,q)=H(p)+D_{\mathrm{KL}}(p\parallel q), where H(p)=-\sum_x p(x)\log p(x) is the intrinsic uncertainty of the target distribution and D_{\mathrm{KL}}(p\parallel q) is the additional discrepancy caused by using the model distribution instead of the target.1,2 When the target distribution is fixed, its entropy is constant, so minimising cross-entropy is equivalent to minimising the forward Kullback-Leibler divergence. The best achievable model within its chosen function class is therefore the one that most closely approximates the data-generating probabilities, not merely the one that maximises the number of correct labels.

This distinction makes cross-entropy more informative than accuracy during optimisation. Accuracy records whether the highest-probability class is correct and ignores the remaining probability mass. A prediction of 0,51 for the correct class and a prediction of 0,99 receive the same accuracy outcome, although they convey very different confidence. Cross-entropy separates them. It can therefore encourage useful probability estimates, support ranking decisions by risk, and provide a basis for comparing models whose classification accuracy is identical. In language modelling, the same principle is applied token by token, and average cross-entropy is closely connected to perplexity through \operatorname{perplexity}=\exp(L) when natural logarithms are used.2

Training benefits and practical complications

Cross-entropy also has a convenient optimisation structure. Combined with a softmax output, its gradient with respect to a logit is \frac{\partial L}{\partial z_k}=q_k-\mathbf{1}[k=y], where \mathbf{1}[k=y] equals one for the observed class and zero otherwise. This compact gradient gives a direct learning signal: the model is pushed to increase the true class probability and decrease probabilities assigned to competing classes. Implementations usually combine softmax and logarithmic calculations in a numerically stable operation, avoiding unnecessary overflow, underflow, or explicit logarithms of rounded probabilities.

Several modelling choices alter what the loss means. Soft targets can represent genuine ambiguity, annotator disagreement, or a teacher model in knowledge distillation rather than a single categorical answer. Label smoothing replaces a one-hot target with a less concentrated distribution, often reducing extreme confidence and improving generalisation, although it can also weaken the fit to precise labels. Class weighting changes the contribution of selected examples when errors on rare or costly classes matter more than errors on common classes. These modifications do not make the objective universally better; they encode a different preference about the consequences of mistakes.

A low average loss does not guarantee trustworthy probabilities. Neural networks can be accurate yet overconfident, particularly after extensive training or under distribution shift. Calibration methods, including temperature scaling, adjust confidence after training, but calibration must be assessed on data representative of the intended deployment setting. Cross-entropy itself evaluates probabilistic quality under the observed data distribution, so it can be dominated by frequent classes and may obscure poor performance on a minority population. Reporting accuracy, class-specific metrics, calibration measures, and subgroup results alongside loss gives a more complete account.

Competing objectives and continuing relevance

The main theoretical appeal of cross-entropy is its connection with maximum likelihood. If a model assigns probability q_\t\th\eta(y\mid x) to the observed label, maximising the conditional likelihood of the training data is equivalent to minimising the negative log-likelihood -\sum_i\log q_\t\th\eta(y_i\mid x_i). This provides a principled bridge between statistical estimation and neural-network training. Yet the target distribution may contain systematic labelling errors, hidden subgroups, or costs that ordinary likelihood does not represent. Robust losses, focal loss, alternative divergences, and explicitly cost-sensitive objectives may be preferable when rare hard examples or asymmetric harms are central.

Cross-entropy remains important because it connects a simple operational rule with a deep statistical interpretation. It is simultaneously a measure of predictive surprise, a negative log-likelihood, a divergence-related objective, and a practical gradient signal for classification systems. Its strengths are clearest when labels are meaningful, probabilities matter, and the training distribution resembles the environment in which predictions will be used. Its limitations appear when data are noisy, classes are imbalanced, confidence is miscalibrated, or the cost of errors is not proportional to logarithmic surprise. Understanding those boundaries prevents the loss from being mistaken for a complete definition of model quality.

 

References

1. Cross-entropy – Wikipedia – 2005-04-13 – https://en.wikipedia.org/wiki/Cross-entropy

2. 28.1 Entropy, Cross-Entropy, and KL Divergence – Dive into … – https://d2l.smola.org/chapter_mdl-information-theory/mdl-information-theory.html

3. Cross-Entropy Loss for Classification – 2026-11-09 – https://www.ultralytics.com/glossary/cross-entropy-loss

4. Cross-Entropy – AI Wiki – 2026-03-18 – https://aiwiki.ai/wiki/cross-entropy

5. Cross entropy loss: explained in 19 Manning books · liveBook – https://livebook.manning.com/learn/concepts/cross-entropy-loss–metric

6. Cross-entropy Loss – Lightly.ai – https://www.lightly.ai/glossary/cross-entropy-loss

7. [PDF] Information Theory Basics 1 Information, Entropy, KL Divergence – https://www.cs.ox.ac.uk/people/varun.kanade/teaching/ML-MT2017/lectures/lecture_inf_theory.pdf

8. Cross entropy loss in Machine Learning System Design – liveBook · Manning – https://livebook.manning.com/learn/concepts/cross-entropy-loss–metric/machine-learning-system-design

9. Cross-Entropy Loss – Computer Vision Online – https://computervisiononline.com/explains/cross-entropy-loss/

10. A Brief Guide to Cross-Entropy Loss – 2026-05-20 – https://www.lightly.ai/blog/cross-entropy-loss

 

Global Advisors | Quantified Strategy Consulting
error: Content is protected !!