7.3 Introduction to interpretability
1. Learn
Section titled “1. Learn”- Anthropic, Transformer Circuits Thread"A Mathematical Framework for Transformer Circuits" (2021), sections on the residual stream and attention heads
- ARENA: Transformer interpretabilitychapter 1, sections 1.1–1.2
- Olsson et al., In-context Learning and Induction Headsthe overview and the definition of induction heads
2. Bridge
Section titled “2. Bridge”The residual stream is a sum. In a pre-norm transformer (4.5) every attention and MLP sublayer reads the stream and adds its output back. So the stream after the last block is the token embedding plus one write per sublayer, and since each head’s write is its attention pattern times its values times its slice of the output matrix, it is a sum over heads too (Elhage et al. 2021, “the residual stream” and “attention heads are independent and additive”). That additivity is what makes the tools below work.
The logit lens. Apply the final norm and the output layer to the stream after an intermediate block, as if it were the last, and see what the model would predict there (nostalgebraist 2020). In GPT-2 the prediction sharpens layer by layer. In other model families (GPT-Neo, BLOOM, OPT, even small ones) early streams are not in the output layer’s basis yet, and the tuned lens fits a small map per layer to correct for that (Belrose et al. 2023).
Heads you can recognise. A head’s attention pattern says where it reads from. A previous-token head attends from each position to the one before. An induction head finds the previous occurrence of the current token and attends to the token after it, so a repeated sequence can be copied; it needs a previous-token head in an earlier layer to tell it what came before each token. Olsson et al. 2022 argue that this circuit drives much of in-context learning. To test whether a head matters, ablate it: zero its output and measure the change in loss.
Probes and their controls. A linear probe is a linear model fitted to predict a feature from the stream at one layer. High accuracy shows the feature is linearly readable there, not that the model uses it. Compare against controls: the same probe on the embedding and on an untrained model, and on a control task with random labels per word type (Hewitt and Liang 2019, section 2). To show use, intervene, as with ablation.
3. Explore
Section titled “3. Explore”Logit lens, attention patterns, ablation and probes: edit exercises/stubs/m7_3_interp.py on your own machine. This task needs PyTorch, which the in-page runner does not have.
pip install torch # CPU build is enough for the tests
mlc check 7.3Then run the lab. Open notebooks/7.3-interpretability.ipynb (about 5 minutes on a CPU) and paste in your 7.3 file. It trains a 4-layer Shakespeare GPT and reads it with the logit lens; probes every layer for the characters one, two and three positions back, against an untrained control; then trains a 2-layer GPT to copy repeated segments, finds its previous-token and induction heads, and ablates them.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.