Intuition What this page is for
The parent note built perplexity from cross-entropy. Here we stress-test it: every kind of input you could ever feed it — confident models, unsure models, the degenerate uniform model, the catastrophic zero-probability token, the length-mismatch trap, the base-mixing trap, and a real-world word problem. By the end there is no scenario left that surprises you (which is fitting for a page about surprise).
Before anything, a one-line reminder of the two tools we lean on the whole way down. Both come straight from the parent, but let's re-anchor them in plain words so nothing is assumed.
Definition The two objects we use everywhere
Per-token probability P i = P ( w i ∣ w < i ) : the number the model produces for "given everything so far, how likely is the actual next token?" It lives in ( 0 , 1 ] . Bigger = the model expected the truth.
Perplexity PPL = ( ∏ i = 1 N P i ) − 1/ N = exp ( N 1 ∑ i − ln P i ) . Read it as: the effective number of equally-good options the model was torn between at each step. See Cross-Entropy Loss and Entropy and Information Content for where the − ln comes from.
Every case class perplexity can throw at you, and the example that nails it.
Cell
Scenario class
What's special
Example
A
Uniform over V tokens
Degenerate "no knowledge" model; PPL = V exactly
Ex 1
B
Perfect model
Every P i = 1 ; lower limit
Ex 2
C
Mixed per-token probs
The everyday geometric-mean case
Ex 3
D
Zero-probability real token
Limiting value → ∞
Ex 4
E
Compare two models, same data
The practical decision use
Ex 5
F
Base trap (ln vs log 2 )
Same answer only if bases match
Ex 6
G
Different tokenizers, same text
N changes → PPL not comparable; use Bits-Per-Character (BPC)
Ex 7
H
Real-world word problem
Weather forecaster analogy, from raw counts
Ex 8
I
Exam twist: PPL → recover a hidden prob
Invert the formula
Ex 9
We now walk each cell. Figures accompany the ones where a picture carries the reasoning.
Worked example Ex 1 — vocabulary
V = 8 , model is uniform
The model always spreads probability equally over V = 8 possible tokens, no matter the context. Find the perplexity of any sequence.
Forecast: guess the number before computing. What would "torn between 8 equally-good words" give?
Each per-token probability. P i = 8 1 for every i .
Why this step? "Uniform over 8" is the definition of splitting 1 into 8 equal shares — see Softmax and Probability Distributions for how a flat logit vector produces exactly this.
Average negative log. − log 2 P i = − log 2 8 1 = 3 bits, and this is the same for every token, so the average H = 3 bits.
Why this step? Perplexity is b H ; we need H first. Base 2 is convenient because log 2 8 = 3 is clean.
Exponentiate. PPL = 2 3 = 8 .
Why this step? b H with the same base b = 2 we used for the log — the base cancels (we prove that cancellation in Ex 6).
Verify: PPL = 8 = V . Look at the figure: 8 equal bars, each height 1/8 ; the model is genuinely choosing among all 8. This is the worst useful case — a model that learned nothing still scores V , so any real model must beat V to be worth anything.
Worked example Ex 2 — every real token predicted with certainty
A (fantasy) model assigns P i = 1 to the token that actually appears, every single step, over a sequence of N = 100 tokens.
Forecast: if the model is never surprised, what is the smallest perplexity can be?
Product of probabilities. ∏ i = 1 100 1 = 1 .
Why this step? Chain rule for the whole-sequence probability; multiplying 1 's stays 1 .
Apply the root. PPL = 1 − 1/100 = 1 .
Why this step? Any root of 1 is 1 ; the − 1/ N power can't push it below 1 .
Interpret the floor. Perplexity can never be less than 1 , because each P i ≤ 1 ⇒ − log P i ≥ 0 ⇒ H ≥ 0 ⇒ b H ≥ 1 .
Why this step? Establishes the lower bound, matching Cell A's upper bound V . Real models live in [ 1 , V ] .
Verify: 1 means "torn between exactly 1 option" = perfectly decided = no puzzle. Consistent with the Language Modeling Objective : minimizing negative log-likelihood drives PPL toward this floor of 1 .
Worked example Ex 3 — three tokens with different confidences
The model gives P 1 = 0.5 , P 2 = 0.25 , P 3 = 0.1 for the three real tokens. Compute PPL.
Forecast: the probs range from confident (0.5 ) to unsure (0.1 ). Will PPL sit nearer 2 or nearer 10 ?
Sequence probability (chain rule). P = 0.5 × 0.25 × 0.1 = 0.0125 .
Why this step? P ( w 1 , w 2 , w 3 ) = P 1 P 2 P 3 ; this is the joint probability the whole line is right.
Geometric mean of the probs. P ˉ = ( 0.0125 ) 1/3 ≈ 0.2321 .
Why this step? Perplexity is 1/ P ˉ ; the 1/ N root is the geometric mean, which is the "typical" per-token probability — it weights the small 0.1 heavily, which is why PPL is closer to 1/0.1 than to 1/0.5 .
Reciprocal. PPL = 1/ P ˉ = ( 0.0125 ) − 1/3 ≈ 4.31 .
Why this step? Negative exponent flips "typical probability" into "typical branching factor."
Verify: the arithmetic mean of the probs is ( 0.5 + 0.25 + 0.1 ) /3 = 0.283 , giving 1/0.283 = 3.53 ; the geometric mean 0.232 gives 4.31 . Geometric mean is always ≤ arithmetic, so PPL is pulled up by the unsure token — matches the intuition that one bad guess hurts. 4.31 sits between the confident 2 and unsure 10 , as forecast.
Worked example Ex 4 — the model says a real token is impossible
Same as Ex 3 but the fourth token is one the model gave P 4 = 0 .
Forecast: what happens to the whole line's score when one token has probability 0 ?
Surprisal of that token. − log P 4 = − log 0 = + ∞ .
Why this step? Surprise blows up as probability → 0 ; "impossible-but-it-happened" is infinite surprise. Trace the curve − log p in the figure as p → 0 + .
Average. H = 4 1 ( finite + finite + finite + ∞ ) = + ∞ .
Why this step? One infinite term dominates any average of finitely many terms.
Exponentiate. PPL = b + ∞ = + ∞ .
Why this step? b > 1 raised to + ∞ diverges.
Verify: the product route agrees: P = 0.5 ⋅ 0.25 ⋅ 0.1 ⋅ 0 = 0 , and 0 − 1/4 = 1/0 = ∞ . One zero destroys everything — this is exactly why we smooth probabilities and why softmax (which outputs strictly positive numbers) is used: it can never emit a hard 0 .
Worked example Ex 5 — Model A vs Model B, identical text
On the same held-out sentence of N = 5 tokens, Model A gives the true tokens probabilities [ 0.4 , 0.5 , 0.3 , 0.4 , 0.6 ] and Model B gives [ 0.2 , 0.3 , 0.1 , 0.25 , 0.2 ] . Which is better?
Forecast: B's numbers are all smaller. Before computing — must B's perplexity be larger?
Model A geometric mean. P ˉ A = ( 0.4 ⋅ 0.5 ⋅ 0.3 ⋅ 0.4 ⋅ 0.6 ) 1/5 = ( 0.0144 ) 1/5 ≈ 0.4275 .
Why this step? Same recipe as Ex 3; the geometric mean is the typical per-token prob.
Model A perplexity. PPL A = 1/0.4275 ≈ 2.339 .
Why this step? Reciprocal of typical prob = effective branching factor.
Model B. P ˉ B = ( 0.2 ⋅ 0.3 ⋅ 0.1 ⋅ 0.25 ⋅ 0.2 ) 1/5 = ( 0.0003 ) 1/5 ≈ 0.1974 , so PPL B ≈ 5.066 .
Why this step? Repeat for B on the same tokens and same N — the only fair comparison.
Verify: PPL A ≈ 2.34 < PPL B ≈ 5.07 , so A wins . A assigns higher probability to what actually happened, so it is less surprised — the whole point of Cross-Entropy Loss . Sanity: smaller per-token probs ⇒ larger PPL, as forecast.
Worked example Ex 6 — does using
ln instead of log 2 change the answer?
Take Ex 1's uniform model (P i = 1/8 ). Compute PPL two ways: with base-2 logs, and with natural logs. Show they match.
Forecast: will ln give a different number than log 2 ?
Base-2 route. H 2 = − log 2 8 1 = 3 bits, PPL = 2 H 2 = 2 3 = 8 .
Why this step? Reproduces Ex 1 as the reference answer.
Natural-log route. H e = − ln 8 1 = ln 8 ≈ 2.0794 nats, PPL = e H e = e 2.0794 ≈ 8 .
Why this step? Libraries compute H in nats; you MUST exponentiate with e , not 2 .
Why they agree (the cancellation). b H b = b − N 1 ∑ l o g b P i = b l o g b ( ∏ P i ) − 1/ N = ( ∏ P i ) − 1/ N . The base b appears once as the log and once as the exponent, and b l o g b x = x — the base evaporates , leaving a base-free quantity.
Why this step? Proves the answer is a property of the probabilities , not of your logarithm choice.
Verify: 8 = 8 . The mistake to avoid (from the parent): computing H in nats then raising 2 H e = 2 2.0794 ≈ 4.23 = 8 — that mixes bases and is wrong.
Worked example Ex 7 — why you can't compare PPL across tokenizers
The text "banana" is encoded two ways. Word tokenizer: 1 token, model gives P = 0.05 . Character tokenizer: 6 tokens b,a,n,a,n,a, model gives each prob 0.5 (letters are easy). Compare the two perplexities.
Forecast: same text, same underlying probability 0.05 of producing "banana" (0. 5 6 = 0.015625 , close-ish). Will the PPLs be comparable?
Word-level PPL. N = 1 , PPL word = 0.0 5 − 1/1 = 1/0.05 = 20 .
Why this step? One token means N = 1 ; the root does nothing, PPL is just 1/ P .
Char-level PPL. N = 6 , product = 0. 5 6 = 0.015625 , PPL char = 0.01562 5 − 1/6 = 0. 5 − 1 = 2 .
Why this step? Six easy tokens ⇒ per-token branching factor only 2 , even though the word was rare.
Verify: 20 vs 2 — wildly different for the same string ! The mismatch comes entirely from N (1 vs 6) and the per-token distribution changing. See Tokenization . The fix : normalize by characters/bytes instead — use Bits-Per-Character (BPC) , which divides by the number of characters (a fixed 6 here) so the comparison is fair.
Worked example Ex 8 — the weather forecaster
Over 4 days the true weather was Sun, Sun, Rain, Sun . A forecaster reports these probabilities for what actually happened : day1 Sun 0.8 , day2 Sun 0.9 , day3 Rain 0.3 , day4 Sun 0.7 . Treat each day as a "token." What's the forecaster's perplexity?
Forecast: the forecaster was confident except on the rainy day. Nearer 1 (perfect) or nearer 2 (coin-flip)?
Product of the day-probabilities. 0.8 × 0.9 × 0.3 × 0.7 = 0.1512 .
Why this step? Chain rule; probability the whole 4-day sequence is called correctly.
Geometric mean. P ˉ = 0.151 2 1/4 ≈ 0.6237 .
Why this step? Typical single-day probability the forecaster assigned to the truth.
Perplexity. PPL = 1/0.6237 ≈ 1.603 .
Why this step? Effective number of outcomes the forecaster was torn between per day.
Verify: ≈ 1.60 sits between 1 (perfect) and 2 (pure coin flip) — the forecaster is decent but the surprise rain (only 0.3 ) pushes it above 1 . Units check: probabilities are dimensionless, so PPL is a pure count of "effective outcomes," as it should be.
Worked example Ex 9 — recover a hidden probability from PPL
A model processes N = 3 tokens. You know P 1 = 0.5 , P 2 = 0.4 , and the reported PPL = 4 . Find the missing P 3 .
Forecast: PPL = 4 is fairly high given P 1 , P 2 are decent. Do you expect P 3 to be large or small?
From PPL back to the product. PPL = P − 1/3 = 4 ⇒ P = 4 − 3 = 64 1 = 0.015625 .
Why this step? Undo the − 1/3 power: raise both sides to − 3 . This inverts the definition.
Divide out the known probs. P 3 = P 1 P 2 P = 0.5 × 0.4 0.015625 = 0.2 0.015625 = 0.078125 .
Why this step? The product is P 1 P 2 P 3 , so isolate P 3 by division.
Check the range. 0.078 ∈ ( 0 , 1 ] ✅ — a valid probability.
Why this step? If it exceeded 1 we'd know the given PPL was impossible for those P 1 , P 2 .
Verify: rebuild PPL: ( 0.5 ⋅ 0.4 ⋅ 0.078125 ) − 1/3 = ( 0.015625 ) − 1/3 = 6 4 1/3 = 4 ✅. As forecast, P 3 ≈ 0.078 is small — one unsure token dragging the PPL up to 4 .
Recall What each cell taught
Uniform model → PPL = V (ceiling) ::: Ex 1
Perfect model → PPL = 1 (floor) ::: Ex 2
Real models live in [ 1 , V ] ::: Ex 1 + Ex 2
One zero-prob token → PPL = ∞ ::: Ex 4
Geometric mean (not arithmetic) controls PPL ::: Ex 3
Compare only on same data ::: Ex 5
Base cancels iff you exponentiate with the same base ::: Ex 6
Different tokenizers are NOT comparable ::: Ex 7
You can invert PPL to recover a probability ::: Ex 9
Mnemonic The bracket to remember
"One to V, or bust." Every honest perplexity lands in [ 1 , V ] — unless a real token got probability 0 , in which case it busts to ∞ .