Causal Mediation Analysis for Interpreting Large Language Models

Elisabetta Rocchetti, Alfio FerraraSEBD 2024

Introduction

Large Language Models (LLMs) have become central to modern AI, yet they remain largely "black boxes." While we can observe their outputs, understanding the internal logic—the specific neural circuits that drive behaviors like gender bias or mathematical reasoning—is a significant challenge. Traditional Explainable AI (XAI) often relies on feature correlations, which can be misleading. This paper advocates for Causal Mediation Analysis (CMA) as a robust framework for mechanistic interpretability, allowing researchers to move from correlation to causation.

The Causal Mediation Framework

CMA treats an LLM as a structural causal model. By intervening on specific internal components, researchers can isolate their functional roles. The framework involves three primary variables:

  1. Intervention ($X$): A controlled change in the input (e.g., swapping "The doctor" for "The man").
  2. Outcome ($Y$): The resulting change in the model's output probability.
  3. Mediator ($Z$): An internal component, such as an MLP layer or an attention head, positioned between the input and output.
Structural Causal Model illustrating the relationship between intervention (X), outcome (Y), and mediator (Z).

The core of this approach lies in counterfactual interventions. By "freezing" or "swapping" internal representations between different model runs, researchers can decompose the Total Effect (TE) of an input change into its Direct Effect (DE) and Indirect Effect (IE).

Applications in LLM Interpretability

The authors apply CMA across three critical domains to demonstrate its utility:

  • Gender Bias: CMA reveals that bias is not uniformly distributed but often localized within middle network layers and specific attention heads.
  • Syntactic Agreement: Interestingly, a model's ability to handle complex subject-verb agreement does not always scale linearly with model size, suggesting that architectural efficiency matters as much as parameter count.
  • Arithmetic Reasoning: The analysis identified a specialized "math circuit" where early MLP modules process operands, intermediate attention blocks manage sequence flow, and late-layer MLPs perform final computation.

Quantifying Effects

To understand how a specific component contributes to a behavior, researchers perform "swapping" interventions. For instance, in a study of gender bias, one might replace the activation of a specific MLP layer in a "neutral" prompt run with the activation it would have had given a "gendered" prompt.

Visualizing an indirect effect intervention where an internal MLP representation (z) is swapped between model runs to measure its causal contribution.

In a hypothetical scenario, an intervention changing "accountant" to "man" might yield a Total Effect of 7.5. By isolating a specific MLP as a mediator, researchers can calculate a Direct Effect (e.g., 3.0) and an Indirect Effect (e.g., 1.2), providing a precise quantification of how much "bias signal" flows through that specific pathway.

Challenges and Future Directions

While CMA offers a powerful lens into LLMs, several hurdles remain:

  • Prompt Sensitivity: Results can vary significantly based on prompt phrasing, complicating comparisons between decoder-only (e.g., GPT) and masked (e.g., BERT) models.
  • Scaling and Normalization: There is currently no absolute scale for causal metrics, making it difficult to compare bias levels objectively across different architectures.
  • Linguistic Confounders: Complex sentence structures, such as those requiring coreference resolution, can muddy the causal signal.

The authors suggest that future work should focus on developing a normalized bias index and more robust "intervention engineering" to ensure consistent interpretability results across the evolving landscape of Large Language Models.

Summary updated

BibTeX
@inproceedings{rocchetti2024causal,
  author = {Elisabetta Rocchetti and Alfio Ferrara},
  title = {{Causal Mediation Analysis for Interpreting Large Language Models}},
  booktitle = {SEBD},
  year = {2024},
  url = {https://openreview.net/forum?id=6yM3MJMWyr},
}
Figure