Sample and training
Cross-entropy loss
A classifier outputs a probability for every class (ŷ). Training needs one number saying how bad that is, given the right answer (y). Cross-entropy is that number: L = −Σ yi ln ŷi.
- Confident and right (ŷ of the true class near 1): L near 0.
- Unsure (10% on every class): L = ln 10 = 2.303.
- Confident and wrong (ŷ of the true class near 0): L grows without limit.
The three runs
Each is a small network trained for 25 epochs, with its predictions for 10 samples saved along the way: handwritten digits (MNIST), small photos (CIFAR-10, a harder task) and next-word prediction on a tiny corpus (Text). Text labels are soft: “the cat sat on” is followed by “the” half the time and “a” the other half.
Try this
- MNIST: press Train and watch the loss fall. Which digit stays hardest?
- CIFAR-10: find a sample whose loss goes up late in training. Is its top guess right?
- Text: how low can the loss go? Compare it with the dashed floor in the Training tab.
- Manual: put 90% on a wrong class. How large is the loss?
For a one-hot label (class k): L = −ln ŷk. In nats; divide by ln 2 for bits.
Why ln?
Minimising cross-entropy is maximising the likelihood the network gives the training labels: the log turns the product of probabilities into a sum. Its gradient through softmax is simply ŷ − y.
| ŷ of the true class | L |
|---|---|
| 1 | 0 |
| 0.5 | 0.693 |
| 0.1 | 2.303 |
| 0.01 | 4.605 |