Transformers, from the inside · Chapter 2

Attention

By Tomáš Sikora · June 24, 2025

An interactive tour of attention beyond the basic heatmap: information-flow arcs, the causal mask, softmax and temperature, induction heads, attention sinks, a taxonomy of every head, the QK/OV split, and head ablation.

Moving past the conventional attention heatmap, the mechanism is treated in successive layers of abstraction: the routing of information between positions, the masking and softmax normalisation that constrain it, and the specialised functions individual heads acquire — copying from context, allocating attention to a sink token, and retrieving a fact to write the answer. All quantities are precomputed from a forward pass of Qwen3-1.7B.

The attention mechanism

Queries, keys and values — the complete attention block.

Information flow and the causal mask

Which positions each token reads, and why only earlier ones.

Scaled softmax

The softmax function, temperature, and the 1/√d normalisation.

Induction heads

The circuit underlying in-context learning.

Attention sinks

Where attention goes in the absence of a relevant token.

A taxonomy of head functions

The functional roles of all 448 heads in Qwen3-1.7B.

Where versus what (QK / OV)

What a head writes, and how the prediction forms with depth.

Which heads are load-bearing

Ablation and gain-scaling to establish causal importance.

Composing larger circuits

Induction, indirect object identification, and docstring circuits.

The limit of pure attention

Rank collapse, and why the residual stream exists.

This is an interactive article — the figures are explorable and require JavaScript to load.

More in this series: The Residual Stream · all posts