Uncovering Intermediate Variables in Transformers using Circuit Probing

Michael A. Lepori, Thomas Serre, Ellie Pavlick

TL;DR

This paper introduces "circuit probing," a novel technique to automatically discover and analyze the specific neural circuits within Transformers that compute hypothesized intermediate variables. By combining the strengths of traditional probing and causal analysis, circuit probing allows researchers to not only identify if a variable is represented but also to causally test its role and pinpoint the exact model parameters involved, offering a more faithful and unified approach to understanding complex model behaviors.

What Problem Does This Paper Address?

Modern neural networks, particularly Transformers, achieve remarkable performance but remain largely "black boxes." Understanding how they arrive at their decisions is a significant challenge. While researchers can hypothesize about intermediate variables (e.g., syntactic properties like noun number) that a model might use, existing tools struggle to rigorously test these hypotheses. Standard probing methods can only tell us if a variable is represented in the model's activations, not if it's causally used in the computation. Causal analysis methods, on the other hand, often require a complete understanding of the model's causal graph, which is impractical for complex, real-world tasks. This gap makes it difficult to truly understand and trust the algorithms learned by these powerful models.

Methods

The core contribution is circuit probing, a new analysis technique that aims to bridge the gap between representation probing and causal analysis. Here's how it works:

  • Hypothesize Intermediate Variables: Researchers start by proposing a specific intermediate variable they believe the model might be computing (e.g., the syntactic number of a subject noun).
  • Trainable Binary Masks: Circuit probing introduces a trainable binary mask over the model's weights. This mask is optimized to isolate a "circuit" – a subset of model parameters – that computes the hypothesized variable.
  • Contrastive Loss: The optimization uses a soft nearest neighbors loss, encouraging outputs from the same class (e.g., singular vs. plural subjects) to cluster together, while pushing different classes apart.
  • Continuous Sparsification: To handle the combinatorial complexity of binary masks, the paper employs continuous sparsification, which anneals a soft mask into a discrete one during training. L1 regularization is used to encourage sparse circuits.
  • Causal Analysis via Ablation: Once a circuit is identified, it can be causally analyzed by ablating (removing) its learned weights. By observing the impact on the model's performance, researchers can determine if the hypothesized variable is indeed causally implicated in the task.

This approach combines the ability to detect representations (like probing) with the ability to test causality (like ablation studies) in a more targeted and automated way.

Datasets

The paper uses a combination of synthetic and real-world datasets:

  • Toy Arithmetic Tasks: Models are trained on simple arithmetic functions (e.g., (a² – b²)(mod P)) to test the method's ability to decipher learned algorithms, reveal modularity, and track circuit development.
  • Multitask Modular Arithmetic: A synthetic task designed to investigate modularity within Transformer models.
  • Grokking Task: A specific arithmetic task designed to study how models learn and generalize over time.
  • Real-world Language Modeling: Pre-trained GPT2-Small and GPT2-Medium models are used to investigate linguistic dependencies like subject-verb agreement and reflexive anaphora.

Key Insights and Ideas

  • Uncovering Causal Circuits: The primary insight is that by optimizing a binary mask, circuit probing can automatically identify specific subnetworks (circuits) that compute hypothesized intermediate variables. This is a significant step beyond simply finding that a variable is represented.
  • Faithfulness to Model Computation: Circuit probing is shown to be more faithful to the model's actual computation than standard linear or nonlinear probing, meaning it's less likely to find spurious correlations or misinterpret representations.
  • Unified Approach: The method provides a single framework to address multiple interpretability questions: algorithm deciphering, modularity analysis, and tracking circuit development during training.
  • Causality is Key: The ability to perform targeted ablations on the discovered circuits is crucial for establishing causal links between intermediate variables and model behavior.
  • Modularity in Transformers: The experiments suggest that Transformers exhibit modularity, with specific circuits for certain computations that can be identified and analyzed.

Key Results

  • Arithmetic Tasks: Circuit probing successfully deciphered the algorithms learned by toy models, revealing that they often computed a² – b² rather than the mathematically equivalent (a + b) × (a – b). It also demonstrated modularity by identifying distinct circuits for shared and task-specific variables.
  • Training Dynamics: The method tracked the continuous formation of circuits during training, showing that the circuit for generalization often forms before the model's overall performance indicates generalization.
  • Language Tasks (GPT2):
    • Circuit probing identified circuits responsible for subject-verb agreement and reflexive anaphora in GPT2-Small and Medium.
  • Ablating these circuits significantly degraded performance on these tasks, while ablating random subnetworks of similar size had minimal impact, providing strong causal evidence.
  • For subject-verb agreement, the attention block in layer 6 of GPT2-Small was identified as crucial. For reflexive anaphora, layer 7's attention block in GPT2-Medium was implicated.
  • The research also explored feature extraction, finding that early MLP layers are responsible for extracting syntactic number features.

Limitations and Future Work

  • Polysemanticity: The authors acknowledge that neurons can be polysemantic (represent multiple concepts), which can complicate the interpretation of circuits. They mitigate this by encouraging sparsity.
  • Circuit Composition: A key limitation is that it's currently unknown how multiple circuits compose within a block to form the final additive update to the residual stream. Understanding this composition is crucial for performing more complex counterfactual interventions.
  • Future Work: The authors suggest future work should focus on understanding circuit composition and developing methods to replace individual variables for counterfactual interventions. They also note that while circuit probing can provide positive evidence for a computation, it cannot yet definitively prove a computation is not implemented.

Summary updated

BibTeX
@inproceedings{lepori2024uncovering,
  author = {Michael A. Lepori and Thomas Serre and Ellie Pavlick},
  title = {{Uncovering Intermediate Variables in Transformers using Circuit Probing}},
  booktitle = {COLM},
  year = {2024},
  url = {https://openreview.net/forum?id=gUNeyiLNxr},
}
Figure