How LLMs work · Prediction, compression and intelligence · Lesson 1
The guessing game
In 1951 Claude Shannon measured how predictable English is by making people guess text one letter at a time. You’re about to play his game, and in doing so you’ll do the exact job a language model does.
Play
There’s a hidden phrase (lowercase letters and spaces). Guess the next character. Wrong guesses get crossed out; keep going until you hit it. We count how many guesses each character took.
Green characters you got first try. Notice where they cluster: the second half of words, and anything after you’ve recognised the phrase.
Where were you most likely to need many guesses?
Counting surprise in bits
If every one of the 27 symbols were equally likely, each character would carry $\log_2 27 \approx 4.75$ bits of information: the number of yes/no questions you’d need to pin it down.
Your guesses tell a different story. When you nail a letter on the first try, it carried almost no information; you already knew it. The bits per character number above is an estimate of how much each character actually told you, worked out from how your guess counts were spread. Shannon’s subjects landed around 1 bit per character. By that measure English is roughly 75% redundant.
You gave the next character probability $0.25$. How many bits of surprise was it? ($-\log_2 0.25$)
Your guesses are a compression scheme
Here’s Shannon’s clever observation. Suppose you have an identical twin: same brain, same guesses. To send them a sentence, you don’t send the letters. You send how many guesses each letter took: 1 1 3 1 1 1 2 1 …
Your twin plays the game, makes the same guesses in the same order, and stops on the guess number you sent. They reconstruct the sentence exactly. And that list is mostly 1s, which compress beautifully.
Real compressors do this with probabilities instead of guess counts (a method called arithmetic coding, lesson 3), costing almost exactly $-\log_2 p$ bits per symbol.
Explain in your own words why the list of guess counts is enough for your twin to rebuild the text.
A language model plays the same game
An LLM reads text so far and outputs a probability for every possible next token (a word or word-piece). Training means adjusting it so the token that actually came next gets a higher probability: fewer bits of surprise, averaged over trillions of tokens.
Illustrative numbers for three contexts (not from a real model):
Look at what each prediction requires. Geography needs a fact. The pattern needs you to spot doubling. To predict the next word of a physics paper well, you’d need to understand the physics. That is the argument for why next-token prediction, pushed hard enough, forces a model to learn about the world. We will test that argument in lesson 5.
Check
Random text drawn evenly from 32 symbols. How many bits per character?
Which would compress worst?
Model A gives the true next token probability 0.5; model B gives it 0.125. How many more bits does B pay for that token?
Why might someone argue that a model which compresses Wikipedia extremely well must “understand” a lot?