We build perplexity from information theory, step by step.
Step 1 — Surprise of one event.
Information content (surprisal) of an event with probability p is −log2p bits.
Why? Rare events (small p) carry more information; −log makes surprise large when p is small and 0 when p=1.
Step 2 — Average surprise = cross-entropy.
Using the chain rule, P(w1,…,wN)=∏i=1NP(wi∣w<i).
The average per-token cross-entropy (in bits) is
H=−N1∑i=1Nlog2P(wi∣w<i)Why the average? We want a length-independent "typical surprise per token."
Step 3 — Perplexity is just 2 raised to that entropy.PPL=2H=2−N1∑ilog2P(wi∣w<i)
Imagine you're guessing the next word in a story. If you're a great guesser, the real word is usually one you thought was likely — you're rarely shocked. Perplexity is like counting how many words you were "torn between" each time. If you were torn between 2 words, perplexity is 2. If you were sure and always right, it's 1 (no confusion). A bad guesser is torn between hundreds of words, so their perplexity is huge. Lower number = smarter guesser.
Perplexity ka matlab simple hai: model kitna "surprise" ho raha hai real text dekh ke. Agar model ko pata hai ki next word kya aayega — yaani woh us word ko high probability deta hai — toh woh surprised nahi hota, aur perplexity kam aati hai. Kam perplexity = accha model. Isko aise socho: har step pe model kitne equally-likely options ke beech confuse hai — agar 2 options ke beech confuse hai toh PPL=2, agar sure hai toh PPL=1.
Formula ka dil ye hai: PPL=P(poora sequence)−1/N. Yahan N-th root isliye lete hain taaki har token ka average (geometric mean) mil jaaye, aur alag-alag length ke texts compare ho saken. Aur ek important connection: perplexity basically cross-entropy ka exponential hai — PPL=eaverage negative log-likelihood. Deep learning training mein hum cross-entropy loss minimize karte hain, matlab hum indirectly perplexity hi kam kar rahe hote hain.
Do practical baatein yaad rakho. Ek: agar model kisi real token ko probability 0 de de, toh −log0=∞, aur perplexity infinite ho jaati hai — isiliye smoothing zaroori hai. Do: perplexity ko sirf same tokenizer aur same text pe compare karo. Alag tokenizer matlab alag number of tokens (N), toh comparison galat ho jaayega. Iss case mein bits-per-character use karo.
Exam ya interview mein bas ye 80/20 pakdo: lower PPL = better, PPL = effective number of choices (branching factor), aur PPL = 2H (entropy se jud़ा hua). Bas itna clear rahe toh perplexity poora samajh gaye.