Show that the cross-entropy of a model q on text from the true distribution p equals H(p)+KL(p∥q), so perplexity can never go below 2H(p). Why can the perplexities of two models with different tokenisers not be compared directly, and how do you convert to bits per character? For a model with perplexity 20 per token and 4.5 characters per token, what is the bits per character?

Sequence models and transformers, Evaluation
Level L3 Intermediate. Length Long. Nature Th+Mat Both.

What's being asked

Whether you can derive the decomposition, link perplexity to entropy, and normalise across tokenisers.

Key idea

H(p,q)=−∑xp(x)log⁡q(x)=H(p)+KL(p∥q)≥H(p) because KL≥0. Perplexity is 2H(p,q) (with logs in base 2).

Steps

  1. Add and subtract log⁡p(x): −∑xp(x)log⁡q(x)=−∑xplog⁡p+∑xplog⁡pq=H(p)+KL(p∥q).
  2. KL≥0 (Gibbs' inequality), with equality only when q=p. So the cross-entropy is minimised by the true distribution, and the minimum value is the entropy of the source.
  3. Perplexity PP=2H(p,q)≥2H(p). A perfect model still has perplexity above 1 if the text has real uncertainty. PP is the effective branching factor.
  4. Per-token perplexity depends on the unit. A tokeniser with larger tokens predicts fewer, harder tokens, so its per-token perplexity is higher even for the same model quality. Comparing perplexities across vocabularies is therefore unfair.
  5. Convert to a common unit: bits per character =log⁡2PPtokencharacters per token. Here log⁡220=4.322 bits per token, so 4.322/4.5=0.960 bits per character.
  6. Bits per byte or per character is also the quantity a compressor would achieve, which links language modelling to compression.

Common mistakes

How long your answer should be

Half a page to a page; 6 minutes.

Last checked on 4 December 2026.

Read this

Previous in Sequence models and transformers: A decoder has 32 layers, 32 query heads of dimension 128 (dmodel=4096) and stores keys and values in 16-bit floats (2 bytes). How large is the KV cache for one sequence of 4096 tokens with multi-head attention (MHA), grouped-query attention with 8 KV heads (GQA), and multi-query attention (MQA, one KV head)? How many parameters does GQA save in the K and V projections?
Next in Sequence models and transformers: Interpolated absolute discounting uses P(w∣v)=max⁡(c(vw)−d,0)c(v)+λ(v)Plow(w) with 0<d<1. Choose λ(v) so that the distribution sums to 1, and prove it. Then explain why Kneser–Ney replaces the lower-order unigram by the continuation probability Pcont(w)=N1+(∙w)N1+(∙∙), and check that this also sums to 1. If c(v)=10 with 4 distinct followers and d=0.75, what is λ(v)?