Where this came from. Bell Labs, 1948. Claude Shannon asked what the telegraph century had never asked properly: what IS information, such that a noisy wire can carry it and a tariff can price it? One paper answered completely — defining the bit, entropy and channel capacity in a single sweep — and seventy-five years later his quantities turned out to be the native language of machine learning. The story is in How the mathematics was forged; the machinery is this module.
This curriculum has been paying Shannon royalties for twenty lessons without naming him: cross-entropy losses, perplexity as “effective branching factor”, KL in t-SNE and RLHF, “training a language model is compression”. This module collects the debt properly. The claim to be earned today: information is a measurable quantity, its unit is the bit, and probability distributions have an exact price tag — after which every loss function you have ever minimized will read differently.
Surprise, axiomatized
How surprising is an event of probability ? Demand three obvious things — certain events carry no surprise (), rarer is more surprising (decreasing in ), and independent surprises add (, since independent probabilities multiply) — and the logarithm is forced, uniquely:
A fair coin flip: 1 bit. A one-in-a-million event: ~20 bits. The entropy of a source is then just its average surprise:
— maximal () when all outcomes are equally likely (you know nothing), zero when one outcome is certain (nothing to learn), and concave between. If expectation is the Probability module’s universal interface, entropy is its reading on the “how uncertain” dial.
The operational meaning: entropy is a price
What makes more than a formula is Shannon’s source coding theorem: entropy is the minimum average number of bits per symbol any code can achieve for the source — attainable (to within a rounding bit) by giving each symbol a codeword of length : short codes for common symbols, long for rare. Morse had the instinct (E is one dot); Shannon proved the limit. Feel the price move:
At skew 0 the distribution is uniform and the readout says H = 3.000 bits exactly — eight equal options, three yes/no questions, no code can beat the naive one, because there is no structure to exploit. Slide the skew up and watch the invoice drop: as probability concentrates, common symbols earn one-bit codes while rare ones pay five or six, and the AVERAGE falls well under 3 — compression as measured structure. That “20 questions” reading is exact: entropy is the expected number of optimal yes/no questions to pin down an outcome. And this widget is secretly a picture of every file on your disk: zip, PNG and MP3 are engines for finding skew and charging −log p for it — which is why already-compressed files won’t compress again (their bytes have been flattened to skew ≈ 0), and why the LLM track could say with a straight face that a language model is a compressor for text.
Cross-entropy: coding with the wrong beliefs
Now the bridge this curriculum crosses daily. Suppose reality emits symbols from , but you built your code for — lengths . Your average cost is the cross-entropy:
always at least the true entropy, with the excess — the price of wrong beliefs — getting its own lesson next. Read your training losses again with this decomposition in hand: minimizing cross-entropy loss is minimizing the coding cost of the data under your model’s probabilities. The MLE lesson proved cross-entropy = negative log-likelihood algebraically; Shannon supplies the meaning: a classifier or language model is literally a codebook, its loss the bits-per-symbol it would spend, and the gap above the data’s own entropy is exactly what remains learnable. Perplexity (, the LLM track’s metric) is this same invoice quoted as a branching factor, and the irreducible term in the scaling-laws lesson is itself — the entropy of human text, the part no model can ever compress away.
Two boundary stones before the next lesson. Differential entropy (continuous distributions) exists and appears in derivations, but is a subtler object — it can be negative and it shifts under changes of units, so treat “the entropy of a Gaussian” as relative, not absolute. Entropy measures the distribution, not the meaning: a shuffled deck and an encrypted secret have identical entropy readings; Shannon priced description, not importance — the same honest boundary the likelihood-truth gap drew in the LLM track.
import numpy as np
p = np.array([0.5, 0.25, 0.125, 0.125])
H = -(p * np.log2(p)).sum()
print(H) # 1.75 bits — vs 2.0 for the naive code
# the price of wrong beliefs: cross-entropy under a mistaken q
q = np.array([0.25, 0.25, 0.25, 0.25])
print(-(p * np.log2(q)).sum()) # 2.0 = H + KL: the wrong-code penalty
# entropy of English letters vs uniform — why text compresses ~50%
# (frequencies rounded from any corpus table)
Exercises
Work these before the next lesson
- Derive the log: show that h decreasing with h(pq) = h(p) + h(q) forces h(p) = −c·log p, and that choosing bits (base 2) vs nats (base e) is only a units choice. Where do nats appear in this curriculum’s losses?
Solution
Worked solutions are part of Premium — unlock all of them for £5/month →
- 5 more exercises — each with a worked solution — are part of Premium. Unlock everything for £5/month →
References
- C. E. Shannon, “A Mathematical Theory of Communication”, 1948 — part I is this lesson; go read the original, it is shockingly friendly.
- T. Cover & J. Thomas, Elements of Information Theory, ch. 2 & 5 — the standard rigorous treatment.
- D. MacKay, Information Theory, Inference, and Learning Algorithms — the book that unified this module with the rest of the curriculum, decades early; free online.