Contents
Entropy, Cross-Entropy and KL Divergence/Chapter 10 of 10
10Summary
- Surprise \log_2\frac1{p}: k bits is as unlikely as k heads in a row; independent surprises add. Rain in Cupertino in July (p=1/310) is 8.28 bits.
- Units: the base sets the unit; 1 nat =1.443 bits. Machine learning uses \ln because softmax, sigmoid and Gaussian outputs are e raised to a power.
- Entropy H(p)=\E_p[\log\frac1p]: the locals’ average surprise, 0.031 bits a day in Cupertino, 0.99 in Miami; zero when certain, at most \log K; the shortest average message.
- Cross-entropy H_{\mathrm{ce}}(p,q)=\E_p[\log\frac1q]: the newcomer’s average surprise, 4.62 bits; as a loss, the average -\log q_\theta(y).
- KL divergence D_{\mathrm{KL}}(p\,\|\,q)=H_{\mathrm{ce}}(p,q)-H(p)\ge0: the price of wrong expectations, 3.63 bits; not symmetric, not a distance, infinite if q=0 where p>0. Forward KL covers modes, reverse KL seeks one.
- Information gain =H(Y)-H(Y\mid X)=I(X;Y): splitting on city gains 0.35 bits.
- Training: minimizing cross-entropy = minimizing KL to the data = maximum likelihood; the loss falls toward the entropy of the data, never below. Perplexity =2^{H_{\mathrm{ce}}}: 101 for GPT-2.