Part 13 / Topic 2 of 6
Next-token prediction
Everything an LLM does reduces to one move: given the text so far, output a probability distribution over the next token. The simplest possible version is a bigram model — count which word follows which:
# examples/03_a_bigram_language_model_next_token.py
# after 'the': {'cat': 3, 'mat': 1, 'dog': 3, 'rug': 1}
# generated: the cat . the cat saw the dog saw
An LLM is this idea with a transformer instead of a count table: context of thousands of tokens, distribution over ~100k tokens, learned from trillions of examples. But the generated text above already shows the essential behaviour — locally plausible, no plan, no truth-checking. Scale improves "plausible" enormously; it does not change the mechanism.
🧪 Quick quiz
- What does an LLM do at each step of generation?
Show the answer
Predicts a probability distribution over the next token — the bigram model is the minimal version: after "the" it chose among cat, dog, mat, rug by their counts.
Done here? The practice set for Part 13 — 4 exercises with solutions — is on the part page.