Lesson 2: Tokens and Next-Token Prediction
A language model does not read words the way you do. Before it can work with text, the text is chopped into pieces called tokens. A token is usually a whole common word, part of a longer word, or a single punctuation mark. The word 'unbelievable', for example, might be split into 'un', 'believ' and 'able', while a common word like 'the' is a single token. The exact splitting depends on the model, but the idea is the same everywhere: text becomes a sequence of numbered tokens, and numbers are what the model can actually compute with.
Why split words at all? Because a model needs a fixed list of pieces it knows — its vocabulary — and that list cannot contain every word in every language, every name and every spelling. Splitting words into parts keeps the list manageable while still letting the model build any word it needs. It also explains some of the model's odd habits: it may be bad at counting letters in a word, because it never sees the letters, only the tokens; and it may treat a rare name strangely, because the name is split into unfamiliar pieces.
One prediction, repeated
Once text is tokens, the model's job is beautifully simple: given the tokens so far, predict the next token. Given 'The cat sat on the', it predicts 'mat' — not because it knows about cats, but because in its training data that sequence of words is most often followed by 'mat'. Then it adds that token to the sequence and predicts the next one, and the next, and the next. A paragraph, an essay, a whole story: all of it is this one prediction, repeated hundreds of times.
The model does not pick the single most likely token every time. If it did, its writing would be repetitive and dull, always choosing the safest word. Instead it samples: it treats its predictions as probabilities and picks from among the likely tokens, sometimes choosing a less likely one. That randomness is what makes its output varied and creative — and it is also why asking the same question twice gives different answers. A setting called temperature controls how adventurous the sampling is: low temperature sticks to the most likely words, high temperature takes more risks, and very high temperature produces wild, often nonsensical text.
The vocabulary trade-off
Every language model faces a trade-off in how it splits text. A large vocabulary with many whole words means each word is a single token, so sentences are short in tokens — but the model must learn a separate embedding for every word, and rare words still have to be split somehow. A small vocabulary with short pieces means the model can build any word, but sentences become long lists of tokens, which costs more to process and leaves less room in the context window. Modern models sit in the middle, with vocabularies of tens of thousands of tokens, learned from data by an algorithm that repeatedly merges the most common pairs of pieces. The practical consequence for you is simple: when a model behaves strangely with a rare name, a long number, or a word in a language it saw rarely, the cause is often tokenisation, not reasoning — the model is working with pieces that do not match the way you think of the word at all.
Everything else in this course grows out of this one idea. Training a language model means teaching it to predict the next token well, across billions of examples. Prompting means giving it a sequence of tokens that steers its predictions in a useful direction. Hallucination — the confident invention of facts — happens because the model is predicting likely words, not checking truth. If you remember only one sentence from this course, let it be this: a language model is a next-token prediction machine, and everything it does is that prediction, repeated.
How text becomes tokens
Token boundaries are decided by the model's vocabulary, not by spelling rules. That is why a model can struggle with tasks like counting letters.
Key Terms
- Token
- A piece of text — usually a whole common word, part of a longer word, or a punctuation mark — that a language model works with.
- Vocabulary
- The fixed list of tokens a model knows; every piece of text it reads or writes is made from this list.
- Next-token prediction
- The model's core task: given the tokens so far, predict the most likely next token, then repeat.
- Sampling
- Choosing the next token from among the likely ones, rather than always picking the single most likely, which gives varied output.
- Temperature
- A setting controlling how adventurous sampling is: low temperature sticks to likely words, high temperature takes more risks.
- Context window
- How many tokens of text a model can consider at once when making its predictions.
Discussion Questions
- Why might a language model be bad at counting the letters in a word, even though it can write whole essays?
- If a model always picked the single most likely next token, what would its writing sound like? Why is sampling better?
- A model gives you a different answer each time you ask the same question. Is that a bug, or a feature of how it works?
Practice Questions
- What is a token?
- Why are long words split into several tokens?
- What is the model's core task?
- What does temperature control?
- Why does asking the same question twice give different answers?
Show answers
- A piece of text — a whole common word, part of a longer word, or a punctuation mark. Models work with tokens, not letters, and every text is chopped into tokens before the model sees it.
- So the model's vocabulary stays manageable while it can still build any word. A fixed list cannot hold every word in every language, so words are built from parts.
- Predicting the next token, given the tokens so far, and repeating. A whole paragraph is just this one prediction, repeated hundreds of times.
- How adventurous the model's sampling is. Low temperature sticks to the most likely words; high temperature takes more risks and can produce nonsense.
- Because the model samples from likely tokens rather than always picking the top one. The randomness in sampling makes its output varied instead of identical every time.