Secure Systems Group
Menu×

Wiki Home

Cross-entropy loss

Definition

A classifier’s last layer emits one real number per class, called the logits. The softmax function exponentiates the logits and normalizes them, producing a probability distribution over the classes. The cross-entropy loss on a labelled example is the negative logarithm of the probability the model assigned to that example’s true label. It is zero when the model puts all its mass on the correct class and grows without bound as that probability falls toward zero.

Averaged over a training set, this loss is the objective that empirical risk minimization drives down with stochastic gradient descent. Minimizing it is the same as maximizing the likelihood the model assigns to the training labels, and it equals the KL divergence from the predicted distribution to the one-hot label distribution plus a constant that the parameters cannot change. Fitting a student to a teacher’s full soft distribution instead of a one-hot label is the same loss with a different target, which is knowledge distillation.

An autoregressive language model applies the identical loss at every token position, over the vocabulary rather than a label set; this is what “next-token loss” names. Its per-token average, exponentiated, is perplexity.

Papers that use this concept

Variants and traps

  • Entropy, cross-entropy, and KL divergence are three different quantities and the names invite conflation. Entropy scores one distribution; cross-entropy scores a predicted distribution against a target; the KL divergence is their difference, and it is the cross-entropy that a trainer actually computes.
  • The averaged loss and the per-example loss carry different information. The average is the training objective; the per-example value is what membership inference and memorization measurements read, and two models with the same average can assign very different losses to the same point.

See also