liveBook · Manning

Context window

As explained in Grokking AI Algorithms, Second Edition

A context window is the maximum sequence of tokens a language model processes as contextual input at one time.

A context window is the maximum number of tokens a language model can look at in one pass. Think of it as the model’s temporary reading space: a 32-token window can use the latest 32 tokens, but cannot see an entire novel at once. section 11.10 section 11.11

The context window matters because it:

  • Limits each training or inference input to a manageable token sequence. section 11.10
  • Determines how much preceding text the Transformer can use when building contextual meaning. section 11.11
  • Acts as a model hyperparameter alongside vocabulary size, width, depth, and attention heads. section 11.11 section 11.35

Turning a long stream into batches

After tokenization, a long document becomes one continuous stream of token IDs. If the context-window size is 32, the stream is divided into 32-token training examples so the model can process one batch at a time. A batching routine takes a start index, slices the next 32 tokens, appends that sequence, and continues until the remaining stream is too short for a complete window. section 11.10

How Grokking AI Algorithms, Second Edition covers it

How deep it goes
Explains the definition, token batching, architecture role, and tuning trade-offs without developing the model’s internal computations.
Examples
Uses a 32-token toy model, token-ID streams, visual batches, and a Python slicing routine.
What it assumes
Assumes token IDs and basic model terminology while establishing token streams and batching through concrete examples.
What you can do after
Apply it via token batching and choose it as a Transformer hyperparameter for the longest required prompt.
How it connects
Connects context windows to tokenization, batch size, Transformers, self-attention, and hyperparameter tuning.

Also explained in

Compare how 22 books explain context window →

Related concepts

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