ContentsThe library

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: tkt_k is

how much of the truth sits on class kk. For an ordinary labelled example one

of those numbers is one and the rest are zero.

FIG 1Cross entropy, in the form that covers every case
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
Two sums. The outer one averages over examples and is the ordinary business of a loss. The inner one is the interesting one, and the next section shows that it almost never has more than one term in it.

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 tt.

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 contents

This 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

The rest of this course

  1. 01The Number a Model Is Really Asked For
  2. 02Three Reasons the Logarithm Is Not Optionalopening only
  3. 03The Loss, Written Out in Fullyou are here
  4. 04Turning Scores Into a Distributionopening only
  5. 05The Simplest Gradient in the Subjectopening only
  6. 06The Floor the Loss Cannot Go Belowopening only
  7. 07What a Perplexity of Twelve Meansopening only
  8. 08When a Low Loss Still Lies to Youopening only

Read alongside