The information content (or "surprisal") of an event with probability p is:
Low probability → high surprise → high information content. If P("cat") = 0.01, the surprisal is −log(0.01) ≈ 4.6 (using natural log). If P("the") = 0.73, the surprisal is −log(0.73) ≈ 0.31 — much less surprising.
Why the log? It makes information additive: the information from two independent events is the sum of their individual informations. log(a·b) = log(a) + log(b). This is the defining property of information.
The entropy H(P) of a distribution P is the expected surprisal:
Entropy measures uncertainty. A fair coin (H = 1 bit) has higher entropy than a biased coin that's heads 99% of the time (H ≈ 0.08 bits). Maximum entropy = uniform distribution (most uncertain). Minimum entropy = deterministic (certain, H = 0).
The cross-entropy H(P, Q) measures how surprised model Q is by data drawn from true distribution P:
In language modeling:
Perplexity = exp(cross-entropy). It can be interpreted as "the effective number of choices the model is choosing between." Perplexity of 10 means the model is as uncertain as if it were picking uniformly from 10 equally likely options. Lower perplexity = better model. GPT-4 achieves perplexity around 3–5 on standard benchmarks — it's effectively choosing between just a few plausible tokens.
Q1: A model assigns P(correct) = 0.001. What is the cross-entropy contribution for this single example (using natural log)?
A. 0.001 B. −ln(0.001) ≈ 6.9 C. 1 − 0.001 = 0.999 D. 0Q2: Model A achieves perplexity 8, Model B achieves perplexity 4 on the same test set. What does this tell you?
A. Model B is about twice as fast B. Model B is less uncertain — it's effectively choosing between 4 equally likely tokens vs. Model A's 8 C. Model A has more parameters D. Perplexity doesn't measure model qualityQ3: Why does cross-entropy use −log(p) instead of just (1−p) as the penalty?
A. −log(p) is traditional — there's no mathematical reason B. −log(p) makes information additive across independent events, explodes as p→0 (infinite penalty for impossible events), and has deep connections to coding theory and maximum likelihood C. (1−p) gives the same results but is slower to compute D. −log(p) ensures the loss is always positive