01Why it matters
How much is a message worth?
"It's sunny in the desert" tells you almost nothing; "it's snowing in the desert" is news. Information is surprise: the less likely an outcome, the more you learn when it happens.
In 1948 Claude Shannon turned that into a number, measured in bits. It sets the limit on how far any file can be compressed, and its cousin, cross-entropy, is the loss function that trains almost every classifier and language model.
02Key parts
The pieces you will see
- surprise
- bits for an outcome with probability : 1 bit for a fair coin flip, 3 bits for a 1-in-8 event.
- entropy H(P)
- The average surprise of a distribution : .
- cross-entropy H(P, Q)
- The average surprise when outcomes follow but you expected .
- KL divergence
- : the extra bits you pay for believing . Never negative.
03See it work
Measure the weather in bits
Sun (1/2) is worth 1 bit, cloud (1/4) 2 bits, rain and snow (1/8) 3 bits each. Weighted by how often each happens, the average is bits. The code 0, 10, 110, 111 achieves exactly that: short codes for common outcomes.
A forecaster who thinks all four are equally likely ( uniform) uses 2 bits each, so they pay extra bits per day. That gap is the KL divergence.
04Predict
Your turn: count the bits
Make 4 predictions: step forward and answer each question before the next step plays.
0 of 4 made05Try it
Drag the distributions
Drag the tops of the bars. The other bars rescale so each distribution still adds up to 1.
- Make uniform: entropy reaches its maximum, .
- Make one outcome almost certain: entropy drops towards 0.
- Pull one of 's bars down to zero while 's stays up: KL shoots to infinity.
06Check yourself
Check yourself
Question 1 of 5
How many bits of surprise is an outcome with probability 1/16?
Your answer comes back in Review in a few days, so it sticks.
Question 2 of 5
Which distribution over 4 outcomes has the highest entropy?
Question 3 of 5
A classifier gives the correct class probability 0.25 on a sample. What is its cross-entropy loss there?
Question 4 of 5
When is KL(P‖Q) zero?
Question 5 of 5
KL(P‖Q) is 0.5 bits. What can you say about KL(Q‖P)?
07Explain it back
Say it in your own words
What does entropy measure, and why does training a model to minimise cross-entropy pull its beliefs towards the truth?
08Recap
What to remember
- Surprise is bits; entropy is the average surprise, at most for outcomes.
- Cross-entropy is the average surprise under a model; KL is its excess over the entropy, never negative.
- A model that rules out something that can happen pays infinite cross-entropy.
- Machine learning minimises cross-entropy, which is the same as minimising KL from the data.