Cross-entropy loss
The conceptWhy an AI model is punished hardest for being sure and wrong
Cross-entropy loss is the score a model gets for each guess: minus the logarithm of the probability it gave to the right answer. A loss is a number training tries to make smaller.
Say a model must guess the word after 'The cat sat on the'. If it gave 'mat' a probability of 1/2, the loss is 1 bit; at 1/8 it is 3 bits. As that probability nears zero, the loss grows without limit.
What it’s forScores how well a model's predicted probabilities match the true answer.
L = −Σ yᵢ · log₂ pᵢ = −log₂ p_correct
- pᵢ
- the probability the model gave to option i, e.g. each word in its vocabulary
- yᵢ
- 1 for the correct option, 0 for all others
- p_correct
- the probability given to the right answer
- L
- the loss in bits; training code usually uses natural log, which only rescales it
What it givesOne number per guess: 0 for a perfect, certain guess, and larger the less the model expected the truth.
- p_correct = 1/2 → L = −log₂(1/2) = 1 bit
- p_correct = 1/4 → L = 2 bits
- p_correct = 1/8 → L = 3 bits