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.

0characters
–right first try
–bits per character

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?

The first letter of a word, before you know the topic, is where the real uncertainty is. Once a word starts, spelling constrains it; once you see the phrase, meaning constrains everything. Spaces are usually easy because you can tell when a word is complete.

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$)

$0.25 = 2^{-2}$, so $-\log_2 0.25 = 2$ bits. Each halving of the probability adds one bit.

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.

Because the twin’s guessing is deterministic and identical to yours. Given the same text so far, they’ll make the same sequence of guesses, so “it was your 3rd guess” points at exactly one character. The shared predictor does the heavy lifting; only the surprises need sending.

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?

$\log_2 32 = 5$, because $2^5 = 32$. Five yes/no questions pick one of 32 equally likely symbols, and no predictor can do better on truly random text.

Which would compress worst?

Random passwords are designed to be unpredictable, so no predictor gets them cheaply. Contracts are among the most predictable text there is: boilerplate everywhere.

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?

A pays $-\log_2 0.5 = 1$ bit. B pays $-\log_2 0.125 = 3$ bits. The difference is 2 bits. Training loss for an LLM is this cost averaged over tokens (usually in nats rather than bits, but same idea).

Why might someone argue that a model which compresses Wikipedia extremely well must “understand” a lot?

To compress well it must predict well, and Wikipedia is full of text whose continuation depends on facts, causes, arithmetic and reasoning. Every bit saved reflects some regularity the model has captured. Whether that amounts to understanding is the debate in lesson 6, but the pressure toward modelling the world is real.