Inferensys

Glossary

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.
Governance lead reviewing model governance framework on laptop, policy documents visible, executive office setup.
MECHANISTIC INTERPRETABILITY

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.

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.

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.

MECHANISTIC INTERPRETABILITY

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.

01

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.

02

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.
03

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.

04

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.
05

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.
06

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.
METHODOLOGICAL COMPARISON

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.

FeatureCausal Mediation AnalysisLinear ProbingAblation

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

CAUSAL MEDIATION ANALYSIS

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?"

Prasad Kumkar

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.