liveBook · Manning

Next-token prediction

As explained in Introduction to Generative AI, Second Edition

Next token prediction is a language-model training objective that predicts the subsequent token from preceding context.

Type “A good location for a romantic honeymoon is…” and a language model must decide what comes next. Next-token prediction is the training task of guessing the next token—a unit of text—from the words that precede it. During training, the model makes many such guesses and adjusts its weights when the correct token differs from its prediction. section 2.3

For text generation, the model cannot look ahead at words that have not yet been written. This is called autoregressive prediction: each new prediction depends on what came before. A bidirectional model instead uses words on both sides of a missing token. In “They flew to _____ and had dinner in front of the Eiffel Tower,” the later words make “Paris” easier to infer. That approach helps with understanding context, but it differs from generating a continuation. section 2.3

Next-token prediction serves both pretraining and supervised fine-tuning. In fine-tuning, curated examples of prompts and desired responses steer the same prediction task toward particular outputs, such as following instructions, rather than merely producing coherent text. section 2.9

A plausible answer to an impossible question

Asked when the Golden Gate Bridge was transported across Egypt, GPT-3 gave a confident date instead of challenging the premise. Predicting a plausible continuation can produce an answer-shaped response even when the question describes something that never happened. Next-token prediction helps explain this risk; a fluent completion is not, by itself, evidence that a claim is true. section 5.7

Figure 5.9 The probabilities produced by an LLM in predicting the next token in a sentence
A screenshot of a phone

AI-generated content may be incorrect.

A figure shows probabilities produced while an LLM predicts the next token in a sentence. section 5.7

How Introduction to Generative AI, Second Edition covers it

How deep it goes
Explains repeated guesses and weight adjustments, then contrasts autoregressive and bidirectional context without giving implementation details.
Examples
Uses honeymoon completions, an Eiffel Tower clue, and a false-premise Golden Gate Bridge question.
What it assumes
Defines autoregression through a plain-language comparison with bidirectional prediction rather than assuming familiarity with either term.
What you can do after
Evaluate/understand why fluent generated answers can still be wrong or fail to challenge a false premise.
How it connects
Connects autoregressive models, bidirectional models, self-supervision, supervised fine-tuning, and hallucinations.

Also explained in

Compare how 9 books explain next-token prediction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Introduction to Generative AI, Second Edition. The section links point to the parts of the book it draws on.