Mechanistic Interpretability
Circuits, features and superposition inside transformers.
Every weight of a transformer is visible, yet what it computes is not. Mechanistic interpretability tries to reverse-engineer trained networks into features and the circuits that connect them. This lesson covers the toolkit (probes, attributions, causal patching), the circuit view of attention, why features end up in superposition, and how sparse autoencoders try to undo it.
What you’ll learn
- Distinguish probing, attribution and activation patching, and prove the completeness property of integrated gradients.
- Decompose an attention-only transformer into direct, QK and OV paths, and describe circuits found this way.
- Explain superposition with a toy model, and derive the sparsity at which sharing one dimension between two features beats dedicating it to one.
- Formulate sparse autoencoders as dictionary learning, derive the shrinkage caused by the L1 penalty, and weigh what they have found against their limitations.
Questions and tools
Interpretability asks what information an activation encodes, which components cause a behavior, and what algorithm the weights implement. The mechanistic program works bottom-up. It looks for features, directions in activation space that track interpretable properties, and circuits, the weighted subgraphs that compute features from other features through the residual stream (Attention & Transformers).
| Method | Question | Caveat |
|---|---|---|
| Probing: a classifier, usually linear, on frozen activations (Alain & Bengio, 2016) | Is property decodable at layer ? | Decodable is not used. A flexible probe can learn the task itself, so compare with control tasks (Hewitt & Liang, 2019) and test causally. |
| Attribution: gradients, integrated gradients, SHAP (Explainability Methods) | Which inputs or units did this output depend on, locally? | Gradients are local and saturate; plausible-looking attributions can fail sanity checks. |
| Activation patching: replace an activation with its value on another input (Vig et al., 2020; Meng et al., 2022) | Is component causally sufficient or necessary for the behavior? | Results depend on the corrupted input and the metric; patching one component at a time misses redundancy. |
Differentiate along the straight path with the chain rule, and integrate:
Activation patching measures a component's indirect effect: run the corrupted input , set component to its activation on the clean input, and record the change in a metric , such as the logit difference between the right and a wrong answer. Attribution patching estimates every component's effect at once with a first-order Taylor expansion, from two forward passes and one backward pass:
Integrated gradients is the same idea integrated along a path instead of linearized at one end. By completeness, its attributions add up exactly to the change in output; the one-step estimate does so only when is linear in the activations.
Circuits: reading attention as paths
Elhage et al. (2021) read an attention-only transformer as a sum of paths. With embedding , unembedding and, for head , the QK matrix and OV matrix (The Mathematics of Attention), a one-layer model without MLPs and ignoring layer normalization maps one-hot token rows to logits:
Landmark circuits found this way, in small models or small pieces of larger ones:
- Induction heads (Elhage et al., 2021; Olsson et al., 2022), with causal evidence in attention-only models.
- Indirect object identification in GPT-2 small: after "When Mary and John went to the store, John gave a drink to", the model predicts "Mary". Path patching revealed 26 attention heads in 7 classes, including heads that detect the duplicated name, heads that suppress it and "name mover" heads that copy the other name (Wang et al., 2023).
- Modular addition. A one-layer transformer trained on represents inputs as sines and cosines at a few frequencies and combines them with . Its delayed generalization ("grokking") coincides with this circuit forming and the memorizing solution being cleaned up (Nanda et al., 2023).
Circuit discovery can be partly automated by patching edges and pruning those that do not matter (Conmy et al., 2023). A circuit is judged by faithfulness (does it alone reproduce the behavior?), completeness and minimality, all measured by patching and all dependent on the corrupted inputs chosen.
In a one-layer attention-only transformer, which matrix tells you which output tokens head promotes when it attends to token ?
- Row of
- The attention pattern
Show the answer
C. Row of
The OV circuit maps the attended token's embedding through into the residual stream and on to the logits: row lists the logit change for every output token. The QK circuit decides where the head attends, not what it writes.
Superposition
Individual neurons are often polysemantic, responding to unrelated inputs. Elhage et al. (2022) explain this with superposition: when features are sparse, a network can represent more features than it has dimensions by giving them nearly orthogonal directions and tolerating interference (Representation Learning covers the geometry). Their toy model compresses features into dimensions and reconstructs them:
Take equally important features, , and compare two candidate solutions. Dedicated: stores exactly and predicts by a constant bias, its mean , so the loss is the variance of :
Antipodal superposition: and , so , and . With at most one feature active, the ReLU filters the interference and reconstruction is exact. With both active, both estimates err by the smaller value, and for independent uniforms:
Superposition wins when ; divide by to get :
Only two hand-picked solutions are compared, not the optimum over all and , but the mechanism is general: interference costs scale with how often features co-occur, , while dropping a feature costs in proportion to how often it occurs, . Sparse enough features are cheaper to share than to drop, so polysemantic neurons should be expected.
At sparsity , what is the ratio of the two solutions above?
Show the answer
0.11
and , a ratio of about : at 90% sparsity, sharing the dimension costs about a ninth as much as dropping a feature.
Sparse autoencoders: undoing superposition
If activations are sparse combinations of many feature directions, with most , recovering the directions is dictionary learning (sparse coding appears in Autoencoders & Latent Spaces). A sparse autoencoder (SAE) learns an overcomplete dictionary of features:
Take one feature with a unit-norm decoder column, and let be its ideal activation. The optimal code solves a one-dimensional problem:
Setting the derivative to zero and respecting gives soft thresholding: small activations are zeroed, and every active feature is underestimated by .
This shrinkage biases reconstructions toward zero and ties sparsity and fidelity to a single knob. Later variants choose which features fire without penalizing their size: TopK SAEs keep the largest pre-activations (Gao et al., 2024), and gated and JumpReLU SAEs separate the decision to fire from the magnitude.
What SAEs found. Bricken et al. (2023) trained SAEs on the 512-neuron MLP layer of a one-layer transformer, with dictionaries of up to 131,072 features. Most features were far more interpretable than neurons, responding to things like DNA sequences, Arabic script or base64 text, and features split into finer ones as the dictionary grew. Templeton et al. (2024) scaled the method to the residual stream of a production model, Claude 3 Sonnet, with up to about 34 million features. They found multilingual and multimodal features for abstract concepts, including safety-relevant ones such as deception and sycophancy, and showed that clamping a feature steers behavior: amplifying a "Golden Gate Bridge" feature made the model bring up the bridge in almost every reply.
Limitations. An SAE is a model of the model. Its reconstructions leave unexplained error ("dark matter") whose substitution measurably raises the language model's loss; features depend on dictionary size and training run; some features absorb parts of others; and meanings are read off top activations, which can mislead. Evidence on whether SAE features beat simple baselines such as linear probes on practical tasks is mixed. Newer work replaces layers with sparse transcoders and traces attribution graphs through them, extending circuit analysis to large models one prompt at a time.
Key takeaways
- Probes test what is decodable, attributions what an output depends on locally, and activation patching what is causally sufficient or necessary; integrated gradients satisfy completeness, .
- An attention-only transformer is a sum of paths: a direct path plus, per head, a QK circuit (where to attend) and an OV circuit (what to write). Composed heads give induction circuits, and full circuits are known for indirect object identification and modular addition.
- Superposition stores more sparse features than dimensions because interference scales with co-occurrence and dropping with frequency ; polysemantic neurons follow.
- Sparse autoencoders learn overcomplete feature dictionaries, and the L1 penalty shrinks activations by . They have recovered interpretable, steerable features in production models, but faithfulness, completeness and practical value remain open.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
What does the completeness property of integrated gradients guarantee?
- The attributions sum exactly to
- Each attribution equals that feature's causal effect
- The attributions are all nonnegative
- The choice of baseline does not affect the result
Show the answer
A. The attributions sum exactly to
By the fundamental theorem of calculus along the straight path, . Completeness constrains the total, not how it is divided, and the result depends on the baseline.
You run a corrupted prompt but restore one head's output to its value on the clean prompt, and the logit difference for the correct answer recovers 80% of its clean value. What does this show?
- The head is the only component involved
- The head's output carries information that, in this setup, largely suffices to restore the behavior
- The head is irrelevant
- The head's attention weights explain the decision
Show the answer
B. The head's output carries information that, in this setup, largely suffices to restore the behavior
Restoring a clean activation into a corrupted run tests the sufficiency of that component's information. It does not show uniqueness: other components may carry the same information, and the result depends on how the prompt was corrupted.
In the toy model of superposition, why can a network store more sparse features than it has dimensions?
- Because ReLU networks cannot represent orthogonal directions
- Because the loss ignores rare features
- Because the features are dense and correlated
- Because interference costs scale with co-occurrence, , while dropping a feature costs in proportion to
Show the answer
D. Because interference costs scale with co-occurrence, , while dropping a feature costs in proportion to
In the two-feature calculation, sharing a dimension beats dedicating it once . The ReLU removes negative interference, so features that rarely co-occur barely disturb each other.
An SAE feature with a unit-norm decoder column has ideal activation , and the L1 coefficient is . What activation does the optimal code assign?
Show the answer
C.
Soft thresholding gives . Every active feature is shrunk by , a bias that TopK and JumpReLU SAEs avoid.
Further reading
- N. Elhage et al., "A mathematical framework for transformer circuits," Transformer Circuits Thread (2021).
- N. Elhage et al., "Toy models of superposition," Transformer Circuits Thread (2022).
- T. Bricken et al., "Towards monosemanticity: Decomposing language models with dictionary learning," Transformer Circuits Thread (2023).
- A. Templeton et al., "Scaling monosemanticity: Extracting interpretable features from Claude 3 Sonnet," Transformer Circuits Thread (2024).
- L. Sharkey et al., "Open problems in mechanistic interpretability" (2025).