Log inStart free
LESSON 14.01 · 6 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Perplexity

Watch a model's token probabilities turn into one score: the perplexity.


Pro lesson. Stage 1 is free to watch. Pro opens all 6 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 14.01 · EVALUATION BAY7 TOKENS · LOWEST P 0.172
01
Stage 1 of 6 · Token probabilities
The model predicts each token of a held-out sentence. Each bar is the probability of the true token.
Explain it simply

The model reads a sentence it never saw in training. Before each token, it gives that token a probability. It counts which tokens came after the same context in its 8 training sentences, plus k for every token. A tall bar means the model saw this token coming.

7 bars, one per token of “the dog sleeps on a mat”. The highest probability is 0.618, the lowest 0.172.

test tokensprobability, perplexitybits, cross-entropyvocabulary
p00.51the0.54dog0.31sleeps0.17on0.25a0.32mat0.20</s>0.62held-out sentence · 7 word tokensp(sleeps | dog) = (1 + 0.1) / (5 + 0.1 · 14) = 0.172p00.51the0.54dog0.31sleeps0.17on0.25a0.32mat0.20</s>0.62held-out sentence · 7 word tokensp(sleeps | dog) = (1 + 0.1) / (5 + 0.1 · 14) = 0.172
Toy: an n-gram model counted on 8 short sentences
STAGE 1 / 6
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
pt=c+kC+kV\sy{p}{out}{p_t} = \frac{c + \sy{k}{param}{k}}{C + \sy{k}{param}{k} V}
p=1+0.15+0.1⋅14=0.172p = \frac{1 + 0.1}{5 + 0.1 \cdot 14} = 0.172

Each probability is the smoothed share of times the token followed its context.

Common mix-ups

MYTHA lower perplexity always means a better model.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01With n = 3 instead of 2, does the perplexity of the word model go down?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 6
Unlock the full explainer
  • 5 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.