# Cross-entropy loss

> Canonical: https://skillalmanac.com/glossary/cross-entropy-loss | Last verified: 2026-11-25 | Index status: index-eligible

Cross-entropy loss is a loss function, a score of how wrong a model is, for classification. It compares the probabilities a model gives each class with the true label and is lowest when the true class gets high probability.

Also called: log loss, logistic loss, cross entropy, binary cross entropy, categorical cross entropy.

## In plain language

When a model sorts things into categories, such as spam or not spam, it can say how sure it is: for example, very likely spam. Cross-entropy loss turns that into a penalty. If the model gave a high probability to the right answer, the penalty is small. If it gave a low probability to the right answer, the penalty is large. Training tries to make the total penalty smaller. The score only measures how well the probabilities match the labels you supplied, so wrong or noisy labels teach the wrong lesson. It also says nothing by itself about whether a model is fair, safe or useful.

## Technical definition

For one example, scikit-learn's user guide defines binary log loss as the negative log-likelihood of the classifier given the true label: minus the logarithm of the probability the model assigned to the true label. The multiclass form averages, over samples, the negative log of the predicted probability for each sample's true class. The same guide names log loss, logistic regression loss and cross-entropy loss together. In the Stanford CS231n notes, a softmax classifier turns raw scores into probabilities that sum to one and minimises the cross-entropy between the true distribution and the predicted one; the notes say this corresponds to maximum likelihood estimation.

## How it shows up when you use agents

You usually do not compute cross-entropy loss yourself when you run Claude Code, Codex or Cursor. It belongs to training, the stage where people build or fine-tune a [neural network](/glossary/neural-network). It appears in training logs, in fine-tuning reports and in library documentation, and the Stanford CS231n notes and the scikit-learn guide both describe it.

When you read a training log that shows a falling loss curve, check which data the loss was measured on. A loss on the training data and a loss on held-out data answer different questions, and a number that looks good on data the model has already seen does not show how it will do on new cases. Keep the two separate.

If you evaluate an agent feature, do not treat a loss number as a task score. A loss is a training signal computed from probabilities. A pass rate on real tasks is a different measurement, and a model with a good loss can still fail the task. For the general idea of a training score, see [Loss function](/glossary/loss-function); for how a loss is lowered during training, see [Gradient descent](/glossary/gradient-descent).

What breaks when this is misunderstood: teams compare two runs by loss alone, or quote a training loss as if it were quality. Next action: when you train or fine-tune anything, record the loss on a held-out split next to the training loss, and judge the result with a task-level test as well.

## Common confusions

- **Cross-entropy loss versus accuracy.** Accuracy counts right and wrong labels. Cross-entropy uses the probability given to the true class, so two models with the same accuracy can have different loss.
- **Cross-entropy versus log loss.** The scikit-learn guide names log loss, logistic regression loss and cross-entropy loss together. Binary and categorical cross-entropy are the two-class and many-class forms.
- **Cross-entropy versus mean squared error.** Both are loss functions, but cross-entropy compares predicted class probabilities with labels, while squared error compares numeric values. The choice depends on the task.
- **Myth.** A lower loss means a better model for every purpose. Loss measures fit to the training objective on the data it was computed on; a held-out check and a task-level test answer different questions.

## Worked examples in this catalogue

### [llm-eval-test-sets](https://skillalmanac.com/skills/skill-almanac/llm-eval-test-sets)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill builds and validates an eval dataset for an LLM feature, with a checker for duplicates, missing graders, imbalance and leakage.

Why it exercises the concept: The catalogue has no training skills, so this is a contrast case. Cross-entropy can be a training objective or a held-out evaluation metric for class probabilities. This skill checks eval-set structure rather than computing that loss. Label quality matters for both.

### [split-leakage-check](https://skillalmanac.com/skills/skill-almanac/split-leakage-check)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: The skill checks train, validation and test files for duplicates, shared groups, time and label leakage and prints JSON.

Why it exercises the concept: A loss computed on data that leaked from the training set can look better than it should. This skill is a contrast case for checking the data before trusting a loss number. It does not compute cross-entropy.

### [What Is an LLM? The Facts Agent Users Need](https://skillalmanac.com/learn/what-is-an-llm-for-agent-users)

Status: illustrative example from the item's own documentation, not executed for this page.

What you see: A guide to language models, including an autoregressive next-token illustration and a contrasting BERT masked-token objective.

Why it exercises the concept: The guide is about using models, not training them, so it is a contrast case. Its autoregressive illustration shows one prediction setting in which a probability-based score like this one can be applied.

## Related terms

- [Loss function](https://skillalmanac.com/glossary/loss-function.md)
- [Neural network](https://skillalmanac.com/glossary/neural-network.md)
- [Machine learning (ML)](https://skillalmanac.com/glossary/machine-learning.md)
- [Gradient descent](https://skillalmanac.com/glossary/gradient-descent.md)
- [Supervised learning](https://skillalmanac.com/glossary/supervised-learning.md)
- [Backpropagation](https://skillalmanac.com/glossary/backpropagation.md)

## Sources

- [Metrics and scoring: log loss](https://scikit-learn.org/stable/modules/model_evaluation.html#log-loss), scikit-learn (accessed 2026-11-24)
- [Linear classification: Softmax classifier and cross-entropy loss (CS231n notes)](https://cs231n.github.io/linear-classify/), Stanford University (accessed 2026-11-24)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
