liveBook · Manning

Attention matrix

An attention matrix is a matrix of scores or weights indicating how strongly query positions attend to key positions.

How 3 Manning books explain it

Natural Language Processing in Action, Second Edition

An attention matrix is a matrix of learned or computed weights representing how strongly elements in a sequence should attend to one another.

How it is used
Connects tokens across a sequence while preserving stackable transformer layers and restricting what a text-generation decoder may see.
How deep it goes
Explains sequence-wide multiplication, encoding shapes, and causal masking, but does not derive how attention weights are calculated.
Examples
Uses a four-token question, an encoder word-connection diagram, and causal GPT-2 fine-tuning data.
What you can do after
Evaluate/understand it by tracing which tokens an encoder can connect and why a decoder must block future tokens.

Read how Natural Language Processing in Action, Second Edition explains attention matrix →

Build a Text-to-Image Generator (from Scratch)

An attention map is a matrix of attention probabilities showing how strongly tokens attend to one another.

How it is used
Uses token-to-token probabilities to inspect what a vision transformer attends to while classifying images.
How deep it goes
Explains tensor dimensions, normalization, token selection, aggregation, reshaping, and interpolation, but not attention-score computation.
Examples
Uses CIFAR-10 images, 65-token matrices, 8 × 8 patch grids, and overlays comparing actual and predicted labels.
What you can do after
Diagnose attention behavior with PyTorch by extracting, validating, aggregating, reshaping, and visualizing attention maps.

Read how Build a Text-to-Image Generator (from Scratch) explains attention matrix →

Machine Learning System Design

An attention matrix is a two-dimensional array of attention weights relating positions in one sequence to positions in another sequence.

How it is used
Uses attention plots to validate sequence alignment assumptions, guide training, and locate errors for data-gathering decisions.
How deep it goes
Explains diagonal structure, residual interpretation, and guided-attention loss, but defers attention-module construction details.
Examples
Uses audio-frame-to-character plots, diagonal alignment, training evolution, and residuals around difficult sounds or character combinations.
What you can do after
Diagnose alignment problems with attention plots and use residual patterns to inform targeted data collection.

Read how Machine Learning System Design explains attention matrix →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.