Causal Mediation Analysis is a framework adapted from cognitive science to quantify the causal effect of a specific intermediate representation on a model's final output. It measures the indirect effect by intervening on a mediator variable—such as a neuron or attention head—while holding the direct input-to-output pathway constant, isolating the contribution of a single component.
Glossary
Causal Mediation Analysis

What is Causal Mediation Analysis?
A statistical framework for quantifying how much a model's output depends on a specific intermediate representation by measuring the effect of intervening on that representation.
The technique relies on interchange interventions, where a model's internal activation during a forward pass is replaced with a cached activation from a counterfactual input. By comparing the output change, researchers can decompose a model's computation into direct and indirect causal effects, localizing where specific algorithms or factual associations are implemented within the network.
Key Characteristics of Causal Mediation Analysis
Causal mediation analysis provides a rigorous statistical framework for quantifying how much a model's output depends on a specific intermediate representation by measuring the effect of intervening on that representation.
Average Causal Mediation Effect (ACME)
The ACME is the core metric that quantifies the indirect effect of a treatment on an outcome through a specific mediator variable. In mechanistic interpretability, this translates to measuring how much a model's final prediction changes when you intervene on an intermediate activation, while holding the direct input path constant. The effect is calculated as the difference between the outcome when the mediator is set to its value under the treatment condition versus the control condition. This decomposition allows researchers to isolate the causal contribution of a single neuron, attention head, or layer from the total effect.
Total Effect Decomposition
The total causal effect of an input on a model's output is mathematically decomposed into two distinct pathways:
- Natural Direct Effect (NDE): The effect that flows directly from the input to the output, bypassing the mediator of interest entirely.
- Natural Indirect Effect (NIE): The effect that is transmitted exclusively through the mediator. This decomposition is critical for circuit discovery, as it allows researchers to determine whether a specific model component is a necessary bottleneck for a particular behavior or merely a redundant parallel pathway.
Interventionist Counterfactuals
Unlike purely correlational probing methods, causal mediation analysis relies on do-calculus and counterfactual reasoning. The analysis asks: What would the model's output have been if we had set this specific neuron's activation to a different value? This requires physically intervening in the model's forward pass—clamping, zeroing, or replacing an activation—while leaving all other computations unchanged. This interchange intervention framework is what distinguishes causal mediation from mere correlation, providing evidence that a representation is not just predictive of an outcome but functionally responsible for it.
Mediator Selection and Dimensionality
A critical design choice is selecting the mediator variable from the high-dimensional activation space. Common targets include:
- Residual stream states at specific token positions and layers.
- Attention head outputs before the concatenation and projection step.
- MLP neuron activations within a feed-forward block. Researchers often apply dimensionality reduction or train a sparse autoencoder to decompose polysemantic activations into monosemantic features before using them as mediators, ensuring the intervention targets a single, interpretable concept rather than a superposition of features.
Causal Tracing for Fact Recall
A prominent application of causal mediation analysis is causal tracing, which identifies the specific hidden states responsible for recalling factual associations in language models. The methodology involves three states:
- Clean run: The model processes a factual prompt normally.
- Corrupted run: The subject entity is obfuscated, corrupting the model's ability to recall the fact.
- Restoration run: Clean activations from a single layer and token position are patched back into the corrupted run. By measuring the probability of the correct answer after each restoration, researchers localize the knowledge neurons and MLP layers that mediate factual recall.
Assumptions and Sensitivity Analysis
Valid causal mediation analysis requires satisfying strong identification assumptions:
- Sequential Ignorability: There are no unmeasured confounders between the treatment and mediator, or between the mediator and outcome.
- Consistency: The observed outcome equals the potential outcome under the observed treatment and mediator values. In neural network analysis, these assumptions are often violated due to superposition and distributed representations. Researchers conduct sensitivity analyses by varying the intervention magnitude and location to test the robustness of their causal claims against model-specific noise.
Causal Mediation vs. Related Probing Techniques
A comparison of causal mediation analysis with other techniques used to decode and interpret the internal representations of neural networks.
| Feature | Causal Mediation Analysis | Linear Probing | Ablation |
|---|---|---|---|
Primary Goal | Quantify causal effect of a representation on output | Diagnose what information is linearly encoded | Measure functional importance of a component |
Core Mechanism | Interchange intervention on activations | Train a classifier on frozen representations | Zero out or remove a model component |
Causal Claim | |||
Requires Counterfactual Input | |||
Typical Granularity | Specific neuron, attention head, or layer | Entire layer or residual stream position | Neuron, head, or entire layer |
Output Metric | Average Indirect Effect (AIE) | Classification accuracy or regression loss | Performance drop on a downstream task |
Key Limitation | Requires careful counterfactual dataset design | Correlational; cannot establish causality | Destructive; may disrupt distributed circuits |
Primary Use Case | Localizing factual recall in transformers | Benchmarking encoded linguistic knowledge | Identifying critical model sub-networks |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Frequently Asked Questions
Clear, direct answers to the most common questions about using causal mediation analysis to decode the internal mechanisms of neural networks.
Causal mediation analysis is a statistical framework for quantifying how much a model's output depends on a specific intermediate representation by measuring the effect of intervening on that representation. It adapts the formal tools of causal inference—originally developed for the social sciences—to the internal activations of deep learning models. The core idea is to treat a neuron, attention head, or hidden state as a mediator in a causal chain from input to output. By systematically corrupting, clamping, or swapping that mediator's value and observing the change in the final prediction, researchers can decompose the total effect of an input into a direct effect and an indirect (mediated) effect. This moves beyond correlational probing to establish a causal link between a specific model component and a specific behavior, making it a foundational tool in mechanistic interpretability for answering questions like "Which part of the network is causally responsible for recalling a fact?"
Related Terms
Foundational methods for probing and manipulating a model's internal representations to establish causal mechanisms.
Interchange Intervention
A rigorous causal method that tests whether a model component computes a specific high-level variable. It replaces the activation of a component processing a base input with the activation from a source input that differs only in the target variable. If the model's output changes exactly as predicted by a causal graph, it provides strong evidence that the component represents that variable.
Ablation
A destructive causal technique that removes or zeroes out a model component—such as a specific attention head, neuron, or layer—to measure the resulting drop in performance. The magnitude of degradation infers the component's functional importance. Variants include mean ablation, which replaces an activation with its average value, and zero ablation, which sets it to zero.
Causal Abstraction
A high-level framework for evaluating whether a neural network implements a specific causal algorithm. It involves creating an interchange intervention for each variable in a target causal graph. If the model's internal components align with the graph's variables under these interventions, the model is said to implement a causal abstraction of the algorithm.
Linear Probing
A diagnostic technique that trains a simple linear classifier on top of a frozen model's internal representations. The probe's accuracy reveals what information is linearly decodable at a specific layer. While easy to implement, a high probing accuracy does not guarantee the model uses that information causally, distinguishing it from intervention-based methods.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us