ContentsThe library

The Mathematics of Cross Entropy

What a Perplexity of Twelve Means

Last timeWhat Minimising It Is Really Doing

Perplexity is the loss with the logarithm undone, which turns it into a count of effective choices. It is easy to read and easy to quote misleadingly, and both halves matter.

The loss is a good quantity to optimise and an awkward one to talk about. Nobody

has an intuition for 2.48. Perplexity is what happens when you undo the

logarithm that made the loss convenient in the first place.

FIG 1Perplexity is the loss with the logarithm removed
the average loss per prediction, in natural units
the probability the model gave to the outcome that actually occurred at position n
how many predictions were scored
Note where the average sits. The mean is taken over logarithms and then exponentiated, so perplexity is a geometric mean of the predicted probabilities, inverted. One prediction of near zero probability pulls the whole figure down in a way an ordinary average would not.

Why it reads as a number of choices

Take a model that has learned nothing beyond the size of the vocabulary and

spreads its probability evenly over KK options. Each prediction has probability

1/K1/K, so the loss is log⁡K\log K and the perplexity is exactly KK. That is the

anchor point for the whole interpretation: a perplexity of 12 means the model is

as uncertain as something choosing evenly between twelve options, even though

its actual distribution is nothing of the kind.

FIG 2Perplexity against loss
0.0020000.0040000.0060000.0080000.000.02.85.58.311.0average loss per prediction
effective number of choices
The steepness on the right is why early training looks so dramatic when reported as perplexity and so gentle when reported as loss. Both are the same run. The right-hand end, near 10.8, is where a model over a fifty thousand word vocabulary starts before it has learned anything.

Differences in loss are ratios in perplexity

Because the two are related by an exponential, an additive change in the loss is

a multiplicative change in perplexity. A drop of log⁡2≈0.693\log 2 \approx 0.693 always

halves perplexity, whether you start at 100 or at 4. This is the practical

reason loss is quoted to three decimals: the third decimal is worth a tenth of a

percent of the effective branching factor.

The lesson stops here

3 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 Fullopening only
  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 Meansyou are here
  8. 08When a Low Loss Still Lies to Youopening only

Read alongside