Abstract
BERT-based architectures currently give state-of-the-art performance on many NLP tasks, but little is known about the exact mechanisms that contribute to its success. In the current work, we focus on the interpretation of self-attention, which is one of the fundamental underlying components of BERT. Using a subset of GLUE tasks and a set of handcrafted features-of-interest, we propose the methodology and carry out a qualitative and quantitative analysis of the information encoded by the individual BERT's heads. Our findings suggest that there is a limited set of attention patterns that are repeated across different heads, indicating the overall model overparametrization. While different heads consistently use the same attention patterns, they have varying impact on performance across different tasks. We show that manually disabling attention in certain heads leads to a performance improvement over the regular fine-tuned BERT models.
Introduction
Since its release, BERT (Bidirectional Encoder Representations from Transformers) has dominated leaderboards across nearly every NLP task. However, despite its success, BERT remains a "black box." We know it works, but we don't fully understand how its 144 attention heads (in the base model) contribute to its reasoning. This research investigates whether these heads are learning complex linguistic rules or if they are simply repeating a few basic patterns. It also addresses the question of "over-parameterization": is BERT larger than it needs to be, and does that extra bulk actually hinder its performance on specific tasks?
Methods
The researchers employed a mix of qualitative and quantitative techniques to analyze BERT-base:
- Pattern Categorization: They manually inspected attention maps and identified five recurring patterns: Vertical (attending to special tokens like
[CLS]), Diagonal (attending to previous/next words), Vertical+Diagonal, Block (intra-sentence attention), and Heterogeneous (complex, variable patterns). - Automated Classification: A simple Convolutional Neural Network (CNN) was trained to classify thousands of attention maps into these five categories to quantify their prevalence across tasks.
- Linguistic Probing: FrameNet was used to determine if specific heads were dedicated to identifying semantic roles (e.g., "who did what to whom").
- Head Disabling: To test the necessity of specific heads, they "disabled" them by replacing learned attention weights with a uniform distribution, measuring the subsequent impact on task accuracy.
Datasets
The study utilized a subset of the GLUE (General Language Understanding Evaluation) benchmark:
- MRPC & QQP: Paraphrase detection.
- STS-B: Semantic similarity.
- SST-2: Sentiment analysis.
- RTE, QNLI, & MNLI: Natural language inference and entailment. Additionally, FrameNet was used for semantic role analysis.
Key Insights and Ideas
- Massive Redundancy: Simple attention patterns are repeated across many heads, suggesting significant over-parameterization.
- The "No-Op" Hypothesis: A large portion of attention is dedicated to special tokens (
[CLS]and[SEP]). The authors suggest heads "park" their attention here when no specific linguistic feature is found. - Fine-tuning is "Top-Heavy": Significant changes in attention patterns during fine-tuning occur primarily in the last two layers; earlier layers remain similar to the pre-trained model.
- Addition by Subtraction: Some heads appear detrimental. Disabling them can increase performance, implying they learn "noise" that interferes with specific tasks.
Key Results
The analysis revealed that the "Heterogeneous" category—the most likely to contain complex linguistic information—accounted for only 32% to 61% of heads, depending on the task. The remainder consisted of simple geometric patterns.
Manually disabling the "worst" performing heads led to absolute gains in accuracy. For the RTE task, disabling the entire first layer resulted in a 3.2% improvement. Furthermore, while two specific heads seemed to track semantic roles, disabling them did not hurt performance, suggesting BERT does not rely on these specific links to solve the tasks.
Limitations and Future Work
The study focused exclusively on BERT-base and English. Larger models or languages with different syntactic structures might exhibit different patterns. Additionally, while the study demonstrates the benefits of disabling heads, it does not propose an automated optimal pruning algorithm, which remains a promising direction for future research in model efficiency.
Summary updated