4.2.9 · HinglishTokenization & Language Modeling

Perplexity as a metric

1,578 words7 min readRead in English

4.2.9 · AI-ML › Tokenization & Language Modeling


Perplexity KYA hai?

ki yeh ajeeb power kyun?

  • Raw sequence probability jaise-jaise badhta hai, 0 ki taraf shrink hoti jaati hai (aap bahut se numbers multiply karte ho). Toh yeh alag-alag length ke texts ko compare nahi kar sakti.
  • ==-th root== lene se product ek per-token average (geometric mean) ban jaata hai.
  • Negative exponent "probability" (bada = better) ko "perplexity" (bada = worse) mein flip karta hai, toh yeh ek cost ki tarah behave karta hai.

Cross-entropy se isko HOW derive karte hain (first principles)

Hum perplexity ko information theory se step by step build karte hain.

Step 1 — Ek event ki Surprise. probability wale event ka information content (surprisal) bits hota hai. Kyun? Rare events (chhota ) zyada information carry karte hain; surprise ko bada banata hai jab chhota ho aur jab ho.

Step 2 — Average surprise = cross-entropy. Chain rule use karke, . Average per-token cross-entropy (bits mein) hai Average kyun? Hum ek length-independent "typical surprise per token" chahte hain.

Step 3 — Perplexity bas ko us entropy par raise karna hai.

Step 4 — Dikhao ki yeh definition ke barabar hai.

Toh dono definitions identical hain. ✅

Figure — Perplexity as a metric

Worked examples


Common mistakes (steel-manned)


80/20 core

Recall Feynman: 12-saal ke bachche ko samjhao

Socho tum ek story mein agla word guess kar rahe ho. Agar tum ek great guesser ho, real word usually wahi hota hai jo tumhe likely laga tha — tum rarely shocked hote ho. Perplexity yeh count karna jaisa hai ki tum har baar kitne words ke beech "torn" the. Agar tum 2 words ke beech torn the, perplexity 2 hai. Agar tum sure the aur hamesha sahi rahe, toh 1 hai (koi confusion nahi). Ek bura guesser hazaaron words ke beech torn hota hai, toh unki perplexity bahut badi hoti hai. Chhota number = smarter guesser.


Flashcards

Ek line mein perplexity kya hai?
Exponentiated average per-token negative log-likelihood; equally-likely tokens ki effective number jinmein se model choose kar raha hota hai.
Sequence probability se perplexity ka formula?
.
Perplexity aur cross-entropy ka relation?
jahan base- logs mein average per-token cross-entropy hai.
power kyun lete hain?
-th root isse per-token geometric mean banata hai (length-independent); negative probability ko cost mein flip karta hai.
Lower ya higher perplexity better hai?
Lower better hai — model real text se kam surprised hota hai.
Vocab size pe uniform model ki perplexity?
Exactly (worst case; branching factor recover karta hai).
Agar model ek real token ko probability 0 deta hai toh kya hoga?
Perplexity ho jaati hai; yahi smoothing / zero probabilities avoid karne ki motivation hai.
Alag tokenizers mein perplexities compare kar sakte hain?
Nahi — PPL per-token hai, toh aur distribution change ho jaata hai; sirf identical text aur tokenization pe compare karo.
Code mein natural log se PPL kaise compute hoti hai?
.
Kya log base final perplexity affect karta hai?
Nahi, jab tak same base se exponentiate karo ().

Connections

Concept Map

shrinks with length

per-token average

flips into cost

averaged over tokens

factorizes probability

exponentiate

equals

must match

interpreted as

worst case

Perplexity PPL

Sequence probability P w1..wN

N-th root geometric mean

Negative exponent -1/N

Surprisal -log p

Cross-entropy H

Chain rule product of P wi

Master relation PPL equals b^H

Log base b matches exponent

Effective number of choices

Uniform case PPL equals V