Source-linked AI summary
Do Attention Heads in BERT Track Syntactic Dependencies?
Phu Mon Htut, Jason Phang, Shikha Bordia, Samuel R. Bowman
TL;DR
The paper asks whether individual BERT-style attention heads implicitly track syntactic dependency relations. It extracts relations and trees from attention weights using maximum attention and maximum spanning tree methods, finding specialist heads for some dependency types but no generalist heads that substantially outperform trivial baselines; fine-tuning changes little overall.
Problem
The paper investigates whether individual attention heads in BERT-style models implicitly encode syntactic dependency relations.
Method
The study extracts dependency relations from each attention head using maximum attention weights and maximum spanning trees, comparing them with Universal Dependency trees and baselines.
Results
Some heads track specific dependency types better than baselines, but full-tree extraction does not meaningfully outperform trivial baselines, and fine-tuning produces limited overall change.
Takeaways & Limitations
Attention weights reveal specialist syntactic behavior but do not expose the full syntactic knowledge learned by BERT-style models.
Abstract
from arXiv · showhide
We investigate the extent to which individual attention heads in pretrained transformer language models, such as BERT and RoBERTa, implicitly capture syntactic dependency relations. We employ two methods---taking the maximum attention weight and computing the maximum spanning tree---to extract implicit dependency relations from the attention weights of each layer/head, and compare them to the ground-truth Universal Dependency (UD) trees. We show that, for some UD relation types, there exist heads that can recover the dependency type significantly better than baselines on parsed English text, suggesting that some self-attention heads act as a proxy for syntactic structure. We also analyze BERT fine-tuned on two datasets---the syntax-oriented CoLA and the semantics-oriented MNLI---to investigate whether fine-tuning affects the patterns of their self-attention, but we do not observe substantial differences in the overall dependency relations extracted using our methods. Our results suggest that these models have some specialist attention heads that track individual dependency types, but no generalist head that performs holistic parsing significantly better than a trivial baseline, and that analyzing attention weights directly may not reveal much of the syntactic knowledge that BERT-style models are known to learn.
1 Introduction
The paper asks whether BERT-style models use individual attention heads to track syntactic dependencies and examines this through direct attention analysis. It finds specialist heads for some dependency types, but no generalist head that performs holistic parsing substantially better than baselines.
- The study extracts dependency relations from individual attention heads using maximum attention weights and maximum spanning trees.
- Some BERT and RoBERTa attention heads encode dependency types such as nsubj and obj more accurately than random and positional baselines.
- Maximum-weight extraction finds substantial gains over baselines for nsubj and obj, but only slight gains for advmod and amod.
- Fine-tuning on CoLA has little effect, whereas MNLI improves longer-distance clausal relations while slightly reducing shorter-distance relations.
- Full-tree extraction does not meaningfully outperform baselines, so the attention heads do not provide evidence of holistic syntactic parsing.
2 Related Work
Prior work has extracted dependency structures from Transformer attention and probed BERT’s contextual representations and attention heads for syntactic knowledge. These studies motivate testing whether individual BERT-style heads encode dependency relations directly.
- Earlier methods aggregated Transformer attention or applied maximum spanning trees to extract constituency or dependency structures.
- NMT attention-based extraction often performed no better than simple right-branching baselines, while selected heads also attended to relative positions and syntactic relations.
- BERT probing studies found substantial syntactic knowledge in contextualized representations, including subject-verb agreement and structural information.
3 Methods
The experiments analyze pretrained and fine-tuned BERT-family models by comparing attention-derived dependency relations with Universal Dependencies. They use maximum-attention and maximum-spanning-tree extraction alongside positional, right-branching, and random-model baselines.
- 3.1 Models: The study evaluates pretrained large BERT and RoBERTa models with 24 layers and 16 heads per layer, plus BERT fine-tuned on CoLA and MNLI.
- 3.1 Models: Attention matrices are collected for each layer and head, with tokenization adjustments and sentence-boundary tokens removed before extraction.
- 3.2 Analysis Methods: The MAX method assigns each token the relation to the token receiving its highest attention weight, producing individual arcs that need not form a tree.
- Method 2: Maximum Spanning Tree (MST): The MST method treats attention as a weighted directed graph and uses Chu-Liu-Edmonds to produce a valid directed dependency tree, evaluated as undirected.
- Baselines: Evaluation uses English PUD Universal Dependencies, with most-common positional offsets, right-branching trees, and randomly initialized BERT as baselines.
4 Results
Across MAX and MST extraction, specialist heads recover some dependency types better than baselines, but attention patterns do not yield complete syntactically informative trees. Fine-tuning has limited overall impact, with MNLI improving longer-distance clausal relations while slightly weakening some shorter-distance relations.
- Dependency-type accuracy: Specialist heads outperform baselines substantially for nsubj and obj, while gains are smaller or absent for advmod and amod.MAX results show large margins for nsubj and obj, but only slight gains for advmod and amod; MST does not beat the positional baseline for advmod and amod.
- Fine-tuning: MNLI fine-tuning improves advcl and csubj accuracy by more than 5 absolute points over BERT and CoLA-BERT, while slightly degrading other shorter-distance relations.CoLA fine-tuning produces no substantial accuracy change.
- Dependency-type accuracy: RoBERTa performs worse than other BERT models with MAX extraction but outperforms them with MST extraction.
- Holistic tree recovery: The trained models achieve significantly higher UUAS than random BERT, but their advantage over the right-branching baseline is generally not substantial.The MST method uses the gold-tree root, whereas the right-branching baseline does not.
- Overall interpretation: Overall, attention heads capture specific dependency types but do not reflect the full syntactic knowledge learned by BERT and RoBERTa.Fine-tuning on CoLA and MNLI also has no large impact on UUAS.
5 Conclusion
The study finds that some BERT and RoBERTa attention heads track specific dependency types, but neither extraction method supports generalist heads for holistic parsing. Fine-tuning on CoLA and MNLI does not significantly change the overall self-attention pattern under this analysis.
- Certain attention heads track specific dependency types, but neither method supports generalist heads that perform holistic parsing.
- Fine-tuning on syntax-oriented CoLA and semantics-oriented MNLI does not significantly change the overall self-attention pattern under this analysis.