The Mathematics of Cross Entropy
The Loss, Written Out in Full
Last timeWhy a Logarithm
The loss can now be assembled, and two features appear at once: the sum over classes has one live term, and the value it starts at is known in advance.
Everything needed is now available. The model emits a distribution, the
observed label picks out a number, the logarithm makes the numbers add, and the
average makes the total independent of how many examples there were.
The expression
Write the target as a distribution as well, with one number per class: is
how much of the truth sits on class . For an ordinary labelled example one
of those numbers is one and the rest are zero.
- how many classes there are, which for a language model is the size of the vocabulary
- the target probability of class k on example i, usually one for the observed class and zero elsewhere
- the probability the model gave class k on example i
Writing the target as a distribution is not decoration. It is what allows the
same expression to serve a hard label, a label smoothed deliberately, a label
that is genuinely uncertain, and the output of a teacher model being distilled
into a student. All four are the same loss with different .
The lesson stops here
9 more paragraphs to go
You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.
The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.
See the planThe contentsThis is the reading half
Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.
The contents