Causal Analysis of Syntactic Agreement Mechanisms in Neural Language Models

Matthew Finlayson, Aaron Mueller, Sebastian Gehrmann, Stuart M. Shieber, Tal Linzen, Yonatan Belinkov

TL;DR

This paper uses causal mediation analysis to peek inside neural language models (like GPT-2) and understand how they handle subject-verb agreement. They discovered that models use different strategies depending on whether the subject and verb are close together or separated by other words, and that larger models don't necessarily learn stronger agreement rules.

What Problem Does This Paper Address?

Neural language models (LMs) are remarkably good at predicting the next word, and they can even handle complex grammatical structures like subject-verb agreement. However, why they succeed at this is still a mystery. Researchers can test LMs on specific grammatical challenges (like agreement with distractors), but this only tells us if they get it right, not how. This paper aims to bridge that gap by using causal inference techniques to pinpoint the internal mechanisms responsible for syntactic agreement in LMs.

Methods

The core methodology is causal mediation analysis, a technique borrowed from causal inference. The authors treat the LM as a causal graph where internal components (like neurons) act as mediators. They perform "interventions" on input sentences – specifically, by swapping the grammatical number of the subject (e.g., "author" to "authors") – and observe how this change affects the model's probability predictions for verb agreement. This allows them to quantify the "total effect" of this intervention on agreement preference and then break it down into "indirect effects" attributed to specific neurons or layers. They focus on analyzing the contribution of individual neurons.

Datasets

The study uses synthetically generated prompts based on templates from Lakretz et al. (2019), expanded with relative clause templates. They created prompts across six syntactic structures designed to test subject-verb agreement in various contexts (simple agreement, with distractors, and with relative clauses). The models themselves are pre-trained LMs, primarily GPT-2 in various sizes, but also Transformer-XL and XLNet.

Key Insights and Ideas

  • Two Agreement Mechanisms: Models seem to employ distinct strategies for subject-verb agreement: one for adjacent subject-verb pairs and another for when they are separated by other words. This suggests a more nuanced internal process than a single, unified rule.
  • Size Doesn't Guarantee Strength: Counterintuitively, larger models don't always show stronger preferences for correct agreement. While they might be more accurate overall, the margin of preference between correct and incorrect options isn't necessarily larger.
  • Neuron Specialization: The study found that neurons contributing to agreement are often localized in specific layers, particularly in the upper-middle layers, and that the degree of neuron overlap across different syntactic structures aligns with human intuitions about syntactic similarity.
  • Plural Preference: GPT-2 models consistently show a stronger preference for agreeing with plural subjects than singular ones, possibly because plural verb forms are more "default" in the training data.
  • Adverbs as Cues: Adverbial distractors, surprisingly, seem to increase the preference for correct verb agreement, suggesting they might act as cues that a verb is imminent.

Key Results

  • Total Effects: The "total effect" (a measure of agreement preference) varied significantly across structures and model sizes. Adverbial distractors generally increased total effects, while attractors (like nouns in relative clauses) decreased them.
  • Indirect Effects: For adjacent subject-verb pairs, indirect effects (neuron contributions) increased steadily through the layers. For separated pairs, they peaked in the upper-middle layers and then dropped off. This pattern held across different GPT-2 sizes and for Transformer-XL, but XLNet showed a more uniform pattern across structures.
  • Neuron Overlap: GPT-2 Medium showed a strong correlation between hypothesized syntactic similarity of structures and actual neuron overlap in a specific layer (layer 21), suggesting that the model learns to group neurons for similar syntactic tasks.

Limitations and Future Work

The authors acknowledge that their study is limited to English and specific syntactic structures. They also note that they only analyzed individual neurons and suggest future work could involve intervening on groups of neurons or attention heads simultaneously. They also propose extending the analysis to other phenomena like filler-gap dependencies and negative polarity items, and examining specific verbs and incorrect predictions to understand how models misuse agreement mechanisms.

Summary updated

BibTeX
@inproceedings{finlayson2021causal,
  author = {Matthew Finlayson and Aaron Mueller and Sebastian Gehrmann and Stuart M. Shieber and Tal Linzen and Yonatan Belinkov},
  title = {{Causal Analysis of Syntactic Agreement Mechanisms in Neural Language Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  url = {https://openreview.net/forum?id=_KTiWVuH2p3},
}
Figure