Information Theory: Entropy, Cross-Entropy, KL
Q: How are entropy, cross-entropy and KL divergence related, and why do we minimize cross-entropy?
- Entropy
H(p) = −Σ p log p: average surprise / optimal code length; maximal for the uniform distribution. - Cross-entropy
H(p, q) = −Σ p log q: cost of coding data from p with a code built for q. - KL divergence
KL(p‖q) = Σ p log(p/q) = H(p, q) − H(p) ≥ 0, zero iff p = q; not symmetric. - Training with cross-entropy against fixed labels p minimizes
KL(p‖q_model)(H(p) is constant) = maximum likelihood. - Forward KL
KL(p‖q)is mass-covering (q spreads to cover all of p's modes); reverse KLKL(q‖p)is mode-seeking (used in variational inference; also the KL penalty in RLHF). - Mutual information
I(X;Y) = H(X) − H(X|Y): how much knowing Y reduces uncertainty about X — feature selection, InfoNCE is a lower bound on it. - Perplexity of a language model =
exp(cross-entropy per token).