In this article
For an index target, token cross-entropy is the negative log probability assigned to the correct vocabulary entry after normalization.
A language model emits a score for each vocabulary entry, but a training target often contains only an integer token identifier. Cross-entropy bridges these representations. Its job is to compare the full predicted distribution with the reference event, not to measure how close two token identifier numbers happen to be.
Normalize scores and select the reference entry
For an index target, the loss combines a log-softmax over vocabulary scores with selection of the reference entry and a minus sign. The reference identifier specifies which event occurred. A larger normalized probability for that event produces a smaller loss. Logits need not be positive or sum to one because normalization is part of the operation. Passing already normalized probabilities into an interface expecting logits changes the calculation; the accepted input contract matters as much as the familiar loss name.
A tiny vocabulary separates identity from distance
Imagine vocabulary identifiers assigned to pear, train and stop. A target pointing to train does not mean a prediction of pear is numerically closer than stop in a semantic sense. Identifiers are categorical labels, not an ordered measurement scale. If train receives probability 0.5, its loss is minus the natural logarithm of 0.5. Reassigning vocabulary identifiers together with the corresponding output rows preserves this loss. The actual probability attached to the reference event, rather than the identifier’s magnitude, determines the result.
One-hot notation describes the same event
A one-hot target places its mass on the reference entry. The general cross-entropy expression sums target weights times negative log predicted probabilities; only the reference term remains for a one-hot event. Soft target distributions and label smoothing can deliberately retain additional terms. Those are different target specifications, not automatic properties of every integer-label loss. Be explicit about target form when interpreting reported values. A loss computed against softened targets is not interchangeable with ordinary next-token negative log likelihood without that qualification.
Reduction determines what a reported scalar means
A batch contains many token losses. Summing, averaging and excluding ignored targets produce different reported scalars and gradient scales. First inspect unreduced losses on a tiny example, then document the denominator used for aggregation. Check that the vocabulary axis is the axis normalized and that target positions align with predictions. A plausible scalar does not prove either property. Correct loss interpretation connects the categorical event, the normalization axis, the ignored-position policy and the reduction rule into one reproducible calculation.
Primary research and implementation references
Related engineering context
Reproducible inference stacks: preserving a GPU pilot’s result; A GPU inference benchmark you can trust.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.