Predicting the Next Token in Language Models
Entropy measures how much information, on average, a token in a language carries.
Guessing the Next Word
Imagine someone describing a location to you one word at a time, while you try to anticipate each word before it arrives. Sometimes the next word is almost obvious. At other times you have many plausible options, and any of them could show up. This article is about putting a number on that difference. Language-modeling work uses a quantity called entropy for exactly this purpose.
The way to understand entropy is to notice what changes when a language offers more or fewer possible tokens to choose from. The rest of this article follows that idea step by step: first by tracing a small language, then by reading the number that describes it, and finally by working through a count of tokens.
Tracing a Square-Position Language
Consider a small invented language whose only job is to name positions inside a square. Each token in the language tells you where something sits. The design choice that matters most is how many tokens the language contains, because that choice controls how specific each token can be.
A language that names only two broad regions gives coarse information: each token says whether a position is in the upper or lower part of the square. A language that names four finer regions gives more specific information, because each token pins down a more precise position. The four-token language is the one that carries more information per token. It also asks more of the system that stores and transmits those tokens.
The source states the difference directly: the tokens in the richer language carry more information, and they also need more bits to represent them. Keep this pairing in mind, because the rest of the article depends on it.
What Entropy Averages Over
Entropy measures how much information, on average, a token in a language carries.
The word average is doing real work. A language is made of several possible tokens, and each one may carry a different amount of information. Entropy condenses that collection into one number that describes the typical token. It is a summary of the whole language, not a property of any single token.
Entropy links two ideas that might otherwise seem separate. The first is how much a token tells you. The second is how many bits a token costs to represent. The source gives two consequences: a higher entropy means each token carries more information, and a higher entropy means more bits are needed to represent a token.
Predictability and Entropy
Entropy can also be read as a measure of difficulty. The source describes it as a measure of how difficult it is to predict what comes next in a language. Under this reading, the two-token language and the four-token language differ in how hard it is to guess the next token. Choosing among two possibilities is easier than choosing among four.
A lower-entropy language is therefore more predictable, and a higher-entropy language is harder to predict. The key picture is the shape of the probability spread across possible next tokens. When one token dominates, the spread is peaked and the next token is easy to anticipate. When many tokens are about equally likely, the spread is flat and the next token is hard to anticipate.
Counting Tokens to Find Entropy
The square example gives a concrete pattern: two tokens give entropy 1, and four tokens give entropy 2. The source does not spell out a general rule, but for tokens that are equally likely, the entropy in bits equals the base-2 logarithm of the token count. This rule reproduces both numbers from the example, so it is a useful way to read the pattern.
- 1H is the entropy in bits, the average information carried by a token.
- 2N is the number of equally likely tokens in the language.
- 3log base 2 of N asks how many yes-or-no questions are needed to single out one token from N.
Entropy and bits for the square languages
A language has N equally likely tokens. Find its entropy in bits, and the bits needed to represent each token, for N equal to 2 and N equal to 4.
- 1Two-token language
With N equal to 2, the entropy is $\log_2 2 = 1$. Each token needs 1 bit.
- 2Four-token language
With N equal to 4, the entropy is $\log_2 4 = 2$. Each token needs 2 bits.
- 3Compare
The four-token language has higher entropy, so each token carries more information and needs more bits, matching the source's statement.
Entropy is 1 for the two-token language and 2 for the four-token language. The four-token language carries more information per token and needs more bits per token.
Applying the count to a larger language
Suppose a generated language has 8 equally likely tokens. Find its entropy and the bits per token.
- 1Apply the rule
With N equal to 8, the entropy is $\log_2 8 = 3$.
- 2Read the result
Each token carries 3 bits of information on average and needs 3 bits to represent.
The 8-token language has entropy 3. It carries more information per token than the 2-token or 4-token languages, and it is harder to predict.
Mistakes Learners Make with Entropy
Common mistake Treating entropy as the information of one specific token
Why it failsEntropy is an average over the language's tokens. It describes the typical token, not any single one.
Do this insteadDescribe entropy as the average information per token across the whole language.
Common mistake Reading a higher entropy as a more predictable language
What it looks likeComparing a 2-token language (entropy 1) with a 4-token language (entropy 2), a learner might think the 4-token language is easier to guess.
Why it failsThe source says lower entropy means more predictable. Higher entropy means harder to predict.
Do this insteadHigher entropy means harder to predict and more information per token.
Common mistake Assuming the number of tokens alone decides entropy
Why it failsThe worked counts apply to equally likely tokens. When one token dominates, the spread is peaked and the entropy is lower even if many tokens exist.
Do this insteadConsider how probability is spread across the possible next tokens, not just how many there are.
Practice Predicting Entropy
A language has 16 equally likely tokens. Find its entropy in bits, and say whether it is more or less predictable than the four-token square language.
Hints
- Use the rule that entropy equals the base-2 logarithm of the token count for equally likely tokens.
- Remember that lower entropy means more predictable.
Wrapping Up the Idea
- 1Entropy measures how much information, on average, a token in a language carries.
- 2Higher entropy means each token carries more information and needs more bits to represent it.
- 3Lower entropy means a language is more predictable, and a perfectly predictable token carries no new information.
- 4For equally likely tokens, entropy in bits equals the base-2 logarithm of the number of tokens, which reproduces the square example's values of 1 and 2.
Key Takeaways
- Entropy measures how much information, on average, a token in a language carries.
- Higher entropy means each token carries more information and needs more bits to represent it.
- Lower entropy means a language is more predictable; a perfectly predictable token carries no new information.
- For equally likely tokens, entropy in bits equals log base 2 of the token count, matching the square example's values of 1 and 2.