Tokens and Next-Token Prediction
In this article
- Count the tokens of a text that has been cut into pieces, and say why limits and prices are counted in tokens and not in words.
- Trace a reply step by step: a probability for every possible next token, one token chosen and appended, then the next step on the longer text.
- Tell from a reply whether it most likely ended on the stop signal or at the output limit.
- Explain why a high next-token probability is no evidence that a statement is true.
- Terms defined here: prompt, token, token ID, tokenizer, next-token probability, generation loop.
Overview
Two odd things happen with chat assistants. Sometimes a reply stops in the middle of a sentence. And, as with the made-up tool zorb in Large Language Models, a reply can name an option of a program that does not exist, in the same calm tone as a true answer. Both come from the same small loop that writes every reply. Once you can trace that loop, you can count what a request costs, tell why a reply ended, and say what the model's numbers do and do not measure.
The examples below continue the Eiffel Tower and zorb questions. The tokenizer, its IDs and all the probabilities are invented for illustration.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- From text to tokens
- A probability for every next token
- The generation loop
- What the probability measures
- Sources
- Check yourself, 5 questions