Mechanistic interpretability
What Is Mechanistic Interpretability?
Why this matters:
- Safety: Understanding failure modes requires knowing the algorithm, not just the activations
- Scientific understanding: Neural networks may implement novel algorithms we can learn from
- Debugging: Find where computation goes wrong, not just where output is wrong
- Alignment: Ensure models reason the way we think they do
Core Principles & Approach
1. Circuits Hypothesis
Derivation from first principles:
Start with a transformer layer computation. Real transformers apply LayerNorm (either pre-norm or post-norm). Writing the common pre-norm form:
Why include LayerNorm explicitly? The placement of normalization changes where nonlinearities act and is essential to the residual-stream picture — it normalizes what each sublayer reads from the residual stream while the stream itself accumulates raw sums. Dropping it (as a bare ) misrepresents the actual computation.
Now decompose the attention sublayer. Each of the heads computes a value-weighted sum, then all head outputs are concatenated and a single output matrix is applied:
Equivalently, splitting into per-head blocks acting on each head's slice, we can write the additive-over-heads form:
Here the are not independent projection matrices — they are column-blocks of the single shared . Why the factor? It rescales the dot-product logits so their variance stays regardless of head dimension , keeping the softmax out of saturation. Why this decomposition? Because empirically, individual heads often perform distinct operations (e.g., "previous token head", "induction head").
A circuit is a subset of these heads + MLP neurons that:
- Have strong causal effect on the output
- Implement a coherent algorithm
- Are minimally sufficient (removing components breaks functionality)
2. Activation Patching & Causal Analysis
Why patching over just ablation?
- Ablation shows if a component matters
- Patching shows what information it computes and where that information flows
Derivation of the patching method:
Consider two inputs and where the model succeds on clean but fails on corrupted.
Let be the activation of component on clean input. The patching experiment:
If performance recovers, component causally mediates the correct computation.
Why this works: If computes the key information needed for success, transplanting that computation restores functionality.
3. Superposition & Polysemanticity
Derivation from information theory:
Available capacity: dimensions Required features: features, each active with probability
If features were orthogonal, we'd need dimensions. But with sparsity:
- Expected simultaneous features:
- If , we can pack features via superposition
Cost: Interference between features when multiple activate simultaneously.
Mathematical model (simplified toy example):
Optimize feature vectors to minimize interference:
where are orthonormal basis vectors (the "ideal" non-interfering representation).
Consequence: Individual neurons are polysemantic — they respond to multiple unrelated features.
Key Techniques
Logit Lens & Tuned Lens
Why this works:
In transformers, residual stream accumulates information:
If information is linearly represented, early layers should already contain partial "answers" readable by the unembedding matrix .
Derivation:
The final prediction is:
For intermediate layer:
Comparing to shows how predictions evolve across layers.
Attention Pattern Analysis
Common interpretable patterns:
- Previous token head:
- Induction head: high when token at matches token at (pattern completion)
- Duplicate token head: high when tokens at and are identical
Why analyze patterns? Attention is the main mechanism for moving information between positions. The pattern reveals the routing algorithm.
Connections to Other Interpretability Methods
vs. Feature visualization:
- Feature viz shows WHAT a component responds to
- Mechanistic interpretability shows HOW it computes and WHY that matters for the output
vs. Saliency methods:
- Saliency shows importance for a single decision
- Mechanistic interpretability finds the general algorithm
vs. Probing:
- Probing: "Is information X present?"
- Mechanistic: "How is X computed and used?"
Applications & Implications
- AI Safety: Detect deceptive reasoning circuits before deployment
- Capability analysis: Understand limits of what model can learn
- Scientific discovery: Networks might implement novel algorithms humans didn't design
- Model editing: Surgically modify behavior by targeting specific circuits
Recall Explain to a 12-year-old
Imagine you found a super advanced alien computer that can play chess really well, but you don't understand how it works inside. You have two ways to figure it out: Old way (regular interpretability): Watch it play and notice "oh, when there's a queen on the board, this light blinks." You're just noticing patterns from the outside.
New way (mechanistic interpretability): You carefully open it up and trace the wires. You discover there's a group of parts that work together to "look for pieces that can be captured", another group that "evaluates if the king is safe", and these groups are connected in a specific way to make decisions. You've figured out the actual step-by-step recipe the computer uses!
Mechanistic interpretability is like being a detective who doesn't just watch what the AI does, but figures out the actual "recipe" or "algorithm" it's following, step by step, wire by wire. This is really important because if we're going to trust AI with important decisions, we need to understand not just WHAT it decides, but HOW it thinks!
Connections
- Feature Visualization — complementary: shows WHAT, mechanistic shows HOW
- Attention Mechanisms — attention patterns are primary object of study
- Sparse Autoencoders — tool for decomposing polysemantic neurons
- Transformer Architecture — residual stream structure enables mechanistic analysis
- Probing Classifiers — related but different: presence vs. computation
- Model Editing — applications of mechanistic understanding
#flashcards/ai-ml
What is mechanistic interpretability and how does it differ from post-hoc interpretability? :: Mechanistic interpretability reverse-engineers the learned algorithms neural networks implement by analyzing individual components and circuits. Post-hoc interpretability explains decisions after they're made; mechanistic interpretability explains the computational mechanism that produces decisions.
What is the Circuits Hypothesis?
Why does the attention score include a 1/√d_k scaling factor?
In multi-head attention, is there a separate output matrix W_O per head?
What is activation patching and why is it more powerful than ablation?
What is superposition and why does it cause polysemanticity?
What is the logit lens technique?
What is an induction head and what algorithm does it implement?
Why is correlation between neuron activation and a concept insufficient to claim the neuron "detects" that concept?
How does dictionary learning help decompose polysemantic neurons? :: Dictionary learning finds an overcomplete basis (more features than dimensions) with L1 penalty for sparsity. This decomposes a single polysemantic neuron into multiple interpretable features that were in superposition, separating out the distinct computations.
What are the three criteria for identifying a circuit in a neural network?
Concept Map
Hinglish (regional understanding)
Intuition Hinglish mein samjho
Dekho, yaha core idea ye hai ki neural networks ko hum aksar "black box" maante hai — matlab input daala, output aa gaya, par andar kya ho raha hai pata nahi. Traditional interpretability sirf itna batati hai ki "ye neuron cat detect karta hai." Lekin mechanistic interpretability ek step aage jaati hai — ye poochti hai ki network kaunsa algorithm implement kar raha hai. Jaise ek compiled program ko reverse-engineer karke uske actual computational steps samajhna, na ki sirf input-output mapping dekhna. Isko aise socho jaise ek machine ke gears aur wiring khol kar dekhna, sirf uske panel ka reading padhna nahi.
Ab isme sabse important concept hai circuits hypothesis — matlab network ke andar chhote-chhote subgraphs (circuits) hote hai jo specific, samajhne-layak kaam karte hai, jaise "edge detection" ya "previous token copy karna." Transformer me har attention head alag kaam karta hai, aur inko combine karke poora computation banta hai. Yaha LayerNorm aur scaling jaise details important hai kyunki ye actual computation ka hissa hai — inhe ignore karoge to galat picture banegi. Aur activation patching ek tarika hai jisme hum ek component ko ablate (band) karke dekhte hai ki output pe kitna asar padta hai — isse pata chalta hai ki wo component kis kaam ke liye causally responsible hai.
Ye matter kyu karta hai? Kyunki safety ke liye humein pata hona chahiye ki model kyun fail hota hai, sirf kaha fail hota hai nahi. Debugging me bhi ye help karta hai — galti kaha compute ho rahi hai wo pinpoint kar sakte ho. Aur alignment ke liye ye ensure karta hai ki model us tarah reason kare jaisa hum sochte hai, na ki kisi hidden shortcut se. Basically, jitna better hum model ka andar ka mechanism samajhenge, utna zyada bharosa aur control humein powerful AI systems pe milega — jo aaj ke daur me bahut zaroori hai.