An attention head has four matrices. Queries and keys, computed from the stream at the current position and at earlier ones, determine a pattern, a set of weights saying how much each earlier position is attended to. Values and an output matrix determine what is moved: the weighted sum of value vectors is projected and added to the stream at the current position. The framework splits a head into two circuits (Elhage et al., 2021). The QK circuit, the product of the query and key matrices, decides where the head looks. The OV circuit, the product of the value and output matrices, decides what information it copies and where it writes. A head’s behaviour is the pair of choices.
An attention head has four matrices. Queries and keys, computed from the stream at the current position and at earlier ones, determine a pattern, a set of weights saying how much each earlier position is attended to. Values and an output matrix determine what is moved: the weighted sum of value vectors is projected and added to the stream at the current position. The framework splits a head into two circuits (Elhage et al., 2021). The QK circuit, the product of the query and key matrices, decides where the head looks. The OV circuit, the product of the value and output matrices, decides what information it copies and where it writes. A head’s behaviour is the pair of choices.
Heads in different layers can compose: a later head can read what an earlier head wrote. A head that moves information about the previous token to the current position, followed by a head that uses that information to find an earlier occurrence of the current token and copy what came after it, forms an induction circuit. Evidence that such circuits, which the authors called induction heads, develop during training and are associated with in-context learning in transformer language models was reported by Olsson et al. (2022). I use the induction circuit here because it is the best known example of a two-head circuit, and because it can be built by hand.
Continue with the book
Explore the full treatment, worked examples, and exercises in Next-Generation AI, Explained and Evaluated.
Companion article for Next-Generation AI, Explained and Evaluated, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
