Sparse Interventions in Language Models with Differentiable Masking

Nicola De Cao, Leon Schmid, Dieuwke Hupkes, Ivan Titov

TL;DR

Probing methods often confuse correlation with causation, while brute-force causal interventions cannot scale to combinations of neurons. This paper introduces a differentiable masking technique using a Hard Concrete relaxation and $L_0$ regularization to automatically discover tiny, causal sub-networks (<0.41% of neurons) governing specific linguistic phenomena like subject-verb agreement and gender bias in language models.

What Problem Does This Paper Address?

How do neural language models (LMs) actually use their internal representations? Common interpretability approaches face severe drawbacks:

  1. Diagnostic Probes train classifiers on hidden representations, but showing that a property is encoded does not prove the model uses it to make predictions.
  2. Causal Mediation Analysis perturbs representations (e.g., zeroing out individual neurons) to observe behavioral changes. However, testing individual neurons in isolation misses multi-neuron interactions, while combinatorial testing over subsets is intractable ($O(2^k)$ complexity for $k$ neurons). Furthermore, setting activations to zero does not necessarily "turn off" a feature.

The authors address how to efficiently search the combinatorial space of neuron subsets to find the minimal, causal sub-circuits responsible for a behavior—without breaking unrelated predictions.

Methods

The authors frame causal intervention discovery as a constrained optimization problem:

  • Intervention Formulation: At a chosen time step $i$, a hidden state $h_i$ is altered via a binary mask $m \in \{0, 1\}^k$ and a learned baseline vector $b \in \mathbb{R}^k$: $$\hat{h}_i = (1 - m) \odot h_i + m \odot b$$
  • Objective: Minimize the probability ratio between the original prediction and a target counterfactual prediction (e.g., flipping a verb from singular to plural), while imposing an $L_0$ constraint $C_0(m) \le \alpha$ to enforce extreme sparsity.
  • Differentiable Relaxation: Because binary masks are non-differentiable and standard REINFORCE is slow and noisy, the authors relax $m$ using the Hard Concrete distribution (a stretched and rectified continuous-discrete distribution). This allows pathwise gradient estimation via the reparameterization trick.
  • Lagrangian Relaxation: Dual optimization dynamically tunes the constraint weight $\lambda$ to satisfy the target sparsity level $\alpha$.
  • KL Regularization: A Kullback–Leibler divergence penalty on token emissions across unrelated positions ensures the intervention does not damage general model capabilities.

The method supports both single-step interventions (altering the hidden state only at the critical word, such as the grammatical subject) and every-step interventions (altering representations across all time steps).

Datasets

The authors evaluate a pre-trained two-layer LSTM language model (650 units per layer, 1,300 hidden units total; Gulordava et al., 2018) using two established synthetic benchmarks:

  • Subject-Verb Number Agreement: 11,000 training and 1,000 test sentences from Lakretz et al. (2019) generated from templates with varied syntactic distractors (e.g., "The kid behind the tree avoids / avoid").
  • Gender Bias Detection: 2,673 training and 200 test sentences from Vig et al. (2020) and Lu et al. (2020) combining gender-neutral professions with pronouns (e.g., "The doctor yelled because [he/she]").

No new benchmarks were introduced.

Key Insights and Ideas

  • Extreme Modularity Emerges Naturally: For both tasks, modifying just 2 to 6 neurons out of 1,300 (<0.41%) reliably flips the model's decision with >90% accuracy.
  • Memory Initialization, Not Permanent Storage: In single-step interventions, hidden activations are drastically shifted at the subject token, but subsequent hidden states remain largely uncorrupted (see figure below). This indicates that the identified neurons initialize number/gender memory, which is subsequently handed off to cell states or other circuits.
  • Specialization Without Side Effects: Regularization (penalizing distribution drift on unrelated tokens) had virtually no impact on accuracy or unit selection. The identified units appear strictly dedicated to these specific syntactic and demographic features rather than playing polysemantic roles.

Key Results

  • Subject-Verb Agreement:
  • Single-step: 91.5% flip accuracy intervening on an average of 5.7 units.
  • Every-step: 95.8% accuracy using only 2.0 units. The method successfully recovered unit 776 (previously identified by Lakretz et al., 2019) while discovering complementary units (such as unit 79) missed by single-neuron searches.
  • Gender Bias:
  • Single-step: 93.9% flip accuracy using 5.3 units.
  • Every-step: 99.9% accuracy using only 3.0 units.
  • Efficiency and Superiority over Baselines:
  • Converges in 0.5 hours on a single GPU—at least 7× faster than Score Function Estimation (REINFORCE), which took 3.6–5.2 hours and selected more units.
  • Vastly outperforms Integrated Gradients, which achieved at best 31.5% accuracy even after intervening on 26 units.

Limitations and Future Work

  • Architecture Scope: Experiments focus strictly on standard LSTMs. While the mathematical formulation is architecture-agnostic, the paper does not demonstrate results on modern Transformer-based architectures or attention heads.
  • Intervention Timing Prior: The single-step setup relies on knowing which token to intervene on (e.g., manually targeting the sentence's subject).
  • Synthetic Data Constraints: Evaluations rely on templated, synthetic datasets designed to isolate specific grammatical phenomena rather than naturalistic, complex discourse.

Summary updated

BibTeX
@inproceedings{cao2022sparse,
  author = {Nicola De Cao and Leon Schmid and Dieuwke Hupkes and Ivan Titov},
  title = {{Sparse Interventions in Language Models with Differentiable Masking}},
  booktitle = {BlackboxNLP @ EMNLP},
  year = {2022},
  url = {https://openreview.net/forum?id=fJLv3Q8hJt},
}

Loading related content...

Figure