1.5 Information theory
1. Learn
Section titled “1. Learn”- Chris Olah, Visual Information Theorywhole essay; sections "Codes", "Calculating Entropy", "Cross-Entropy" and "KL Divergence" are the core
- Understanding Deep Learning (Prince)§5.7 Cross-entropy loss (pp. 71–72) and Appendix C.5 Distances between probability distributions (p. 460)
2. Bridge
Section titled “2. Bridge”Every classifier and language model in this course is trained by minimising a cross-entropy (UDL §5.7), and every VAE and diffusion model has a KL term (UDL ch. 17–18). This module explains what those numbers mean.
The surprise of an outcome with probability is : rare events are surprising, certain ones are not. Entropy entropy−∑ p(x) log p(x): the average surprise of p. In nats with natural log, bits with log₂.Introduced in 1.5 Information theory. is the average surprise. It is also the average length of the shortest code for messages drawn from , in bits when the log is base 2 (Olah, “Calculating Entropy”). It is largest for a uniform distribution and zero when one outcome is certain. Use the convention .
Cross-entropy cross-entropy−∑ p(x) log q(x): average code length when data from p is coded using q. H(p, q) = H(p) + KL(p‖q).Introduced in 1.5 Information theory. is the average code length when the data comes from but your code was designed for . Using the wrong code can only cost extra bits, and that extra cost is the KL divergence KL divergence∑ p(x) log(p(x)/q(x)) ≥ 0, zero only when p = q. Not symmetric.Introduced in 1.5 Information theory. (Olah, “Cross-Entropy” and “KL Divergence”):
KL is never negative, and it is zero only when . The proof below needs one inequality: Jensen’s, for the concave log (MML §7.3). KL is not symmetric, so it is not a distance in the geometric sense (UDL App. C.5.1–C.5.2). In particular, if gives zero probability to an outcome that can produce, is infinite, while the reverse direction may be finite. Try it in the widget.
Why this is the loss you will use. Training a classifier minimises the cross-entropy between the data’s labels and the model’s predicted distribution. Since is fixed, that is the same as minimising the KL from the data to the model, and the same as maximising the log likelihood from 1.4 (UDL §5.7). For two Gaussians, KL has a closed form, which the VAE in 6.2 relies on (UDL App. C.5.4). You will confirm it by Monte Carlo in the task.
3. Explore
Section titled “3. Explore”Implement entropy (in any base), cross-entropy, KL with correct handling of zeros, the closed-form Gaussian KL, and a Monte Carlo KL estimator. One test checks KL ≥ 0 on 1000 random pairs.
stubs/m1_5_information.pyLoading starter file…
Prefer your own editor? Edit exercises/stubs/m1_5_information.py and run mlc check 1.5. The tests are identical; import the results on the progress page.
Locally: mlc check 1.5.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.