liveBook · Manning

Next-token prediction

As explained in Deep Learning with R, Third Edition

Next-token prediction is the task of predicting the next token in a sequence given the preceding tokens.

Next-token prediction trains a language model to guess the next word or token from the sequence that precedes it. This makes the model an extremely capable autocomplete: it continues text according to the patterns and probabilities learned from its training data. section 16.3.1

Prompting changes the likely continuation

A short prompt such as “A piece of advice” produces a vague continuation. A prompt beginning “The following brownie recipe is easy to make in just a few steps. You can start by” leads to instructions about melting butter and sugar, because a recipe is the more likely continuation. The model is not interpreting the request conversationally; it is selecting a probable continuation of the supplied text. section 16.3.1

Next-token prediction explains several practical properties of language models:

  • It can produce coherent text without guaranteeing useful or intentional answers. section 16.3.1
  • Longer prompts and explicit role or format instructions can steer the distribution of likely continuations. section 16.3.1
  • It can reproduce familiar patterns while failing on genuinely novel problems or small variations that do not match learned examples. section 19.1.1

Familiarity can overpower correctness

When prompted about the nonexistent 542nd U.S. president, a model continues with the familiar name James A. Garfield. This illustrates how a plausible learned continuation can take precedence over checking whether the premise is valid. section 19.1.1

How Deep Learning with R, Third Edition covers it

How deep it goes
Defines next-token prediction and explains prompting consequences, but does not derive the training loss or token-level internals.
Examples
Uses advice, brownie-recipe, false-president, memorized-trick-question, and novel-puzzle examples to expose continuation and generalization behavior.
What you can do after
Evaluate/understand why generated text can be fluent, prompt-sensitive, plausible, and unreliable on unfamiliar problems.
How it connects
Connects next-token prediction with causal language modeling, prompting, sampling strategies, and in-context learning.

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 Deep Learning with R, Third Edition. The section links point to the parts of the book it draws on.