Pro
Pro lesson

Predicting the next word

Watch a real language model, GPT-2, read text as tokens and write it one token at a time.

This one’s part of How Models Learn Pro — every lesson, every interactive, and new ones as they land. About 12 minutes.

Already Pro? Sign in and you’ll go straight in.

Inside “Predicting the next word”

What you’ll learn

  1. Text becomes tokens
  2. A probability for every token
  3. Rolling weighted dice
  4. One token at a time
  5. How far back can it see?
  6. The loop behind every chatbot

Key terms

Token
A chunk of text — a word, part of a word, a character or even a single byte — that a language model reads and writes.
Tokeniser
The step that splits text into tokens and turns each one into an ID number.
Byte-pair encoding
A way to build a tokeniser’s vocabulary: start from single bytes and repeatedly merge the pairs that appear most often in the training text.
Language model
A model that gives a probability for every possible next token, given the text so far.
GPT-2
A language model released by OpenAI in 2019. The small version has 124 million parameters and a vocabulary of 50,257 tokens, and was trained on about 40 GB of web text.
Sampling
Choosing the next token at random, weighted by the model’s probabilities.
Temperature
A setting that sharpens (below 1) or flattens (above 1) the probabilities before sampling.
Greedy decoding
Always choosing the single most likely next token.
Top-k sampling
Sampling only from the k most likely tokens, ignoring the rest.
Context window
How much of the earlier text a model can see when predicting the next token. GPT-2’s is 1,024 tokens.

Sources