Lesson 5 11 min

Predict the next token

Split text into pieces and trace how selecting one piece changes later guesses.

Learning goal

I can trace two next-token choices and explain how each affects the next prediction.

How it works

A token is a piece of text. Depending on the tokenizer, it can be a word, part of a word, punctuation, or characters that include a space. Many language models assign likelihoods to possible next tokens based on preceding tokens. They may choose a lower-likelihood option and make another prediction using the extended context.

Think of it like this

Think of adding tiles to a sentence. You get a new starting point after each tile. Our tile set uses toy counts and mostly whole words. Real models handle far more pieces and learn many patterns through training.

Worked example

After “The lantern glowed”, the toy list gives softly a count of seven and blue a count of three. Softly leads naturally to “until dawn”. Blue may lead to “but the room stayed dark”. Both paths start with the same context. Their next guesses differ because selecting softly or blue changed the sequence the model works from.

What to remember

Text generation builds a sequence one token at a time. Each new token changes the context for the next one.

  1. Context“The lantern glowed”
  2. Toy next-token countssoftly: 7, blue: 3
  3. Choose softlyLikely next pieces include near and until.
  4. Choose blueLikely next pieces include but and through.
After a choice, the model uses the whole extended context to predict again.Start with “The lantern glowed”. Choose softly or blue. If softly is selected, use the list near and until. If blue is selected, use but and through. Both routes add another piece and continue with updated context.

Key words

Token
A piece of text a language model works with, often a word, part of a word, punctuation, or a space together with other characters.
Language model
A model that learns patterns in language. Many text-generating language models use earlier text to predict likely next pieces of text.
Prediction
A guess based on information, such as guessing how many people will visit a booth next week.
More Language Models lessons

Activity

Build two token paths

Watch context change the next token

The counts are made up, and this activity treats each word as one token. Real models use tokenizers and much larger learned patterns.

Read the steps
  1. Read context. Start with “The lantern glowed”.
  2. Compare options. Toy counts favour softly (7) over blue (3). Both remain possible.
  3. Update context. After “softly”, time or place fits. After “blue”, a contrast may fit.

Try it on paper

Materials Paper strips or a partner to read the alternatives.

  1. Write “The lantern glowed” and a two-option list “softly (7), blue (3)”. Start one path with softly and the other with blue.
  2. For softly, choose near or until and add words that could follow it. For blue, choose but or through and add words that could follow it.
  3. Compare the answers. Underline the token that changed each path. Split “repaint!” two possible ways, such as “re” + “paint” + “!” or “repaint” + “!”.

Talk it through The toy counts illustrate a preference. They are made up. Real token boundaries depend on how the tokenizer was built.

Quick check

1. Which statement about a token is accurate?
Answer and explanation

It can be a word piece or punctuation. Tokenizers use their own vocabulary of pieces. A single printed word can span multiple tokens.

2. Why can the options change after adding “blue”?
Answer and explanation

The chosen piece becomes part of the context. The next prediction uses the extended text. It does not need to retrain the model for this step.