What Does BERT Look at? An Analysis of BERT’s Attention
Kevin ClarkUrvashi KhandelwalOmer LevyChristopher D. Manning
Reveals that individual attention heads in BERT encode distinct grammatical relations and coreference patterns, offering an attention-based analysis framework to interpret linguistic knowledge inside transformer models.
Large neural language models like BERT achieve state-of-the-art performance across natural language processing tasks, yet their internal mechanics remain largely opaque. While prior research focused on evaluating final outputs or internal vector states, the article investigates the internal attention mechanisms of BERT to understand what specific linguistic properties are learned directly from unannotated text.
The article aims to evaluate the surface-level patterns and linguistic capabilities encoded across the 144 attention heads in standard BERT. Specifically, it tests whether individual attention components or linear combinations of them capture grammatical syntax and coreference relationships without explicit task training.
To conduct this evaluation, the study examined attention weight distributions across 1,000 Wikipedia text segments and evaluated grammatical performance using standard benchmark datasets, including the Penn Treebank for dependency parsing and the CoNLL-2012 dataset for coreference resolution. The approach evaluated individual attention heads as direct classifiers and built lightweight diagnostic probes that combine attention weights with fixed word representations, avoiding modifications to the underlying pre-trained model weights.
The analysis reveals several key findings. First, attention heads frequently exhibit broad structural behaviors, such as focusing on adjacent tokens, spreading attention evenly across the sentence, or directing over 50% of their attention mass to separator tokens, which the authors show act as an inactive default state. Second, individual heads specialize heavily in specific grammatical roles; for example, specific heads identify noun determiners with 94.3% accuracy, direct objects of verbs with 86.8% accuracy, and prepositional objects with 76.3% accuracy, outperforming simple positional baselines by 35 to 46 percentage points. Third, a dedicated attention head successfully tracks entity coreference with 65% accuracy, approaching the 69% accuracy of specialized rule-based systems. Finally, combining attention maps with word embeddings in a simple diagnostic parser yields an overall parsing score of 77, indicating that comprehensive syntactic structure is directly encoded in the attention layers.
These findings demonstrate that language models naturally discover hierarchical syntax and coreference purely as an emergent property of self-supervised pre-training, rather than requiring hand-crafted syntactic rules. The results also show significant functional redundancy, as attention heads within the same layer cluster closely in behavior. This redundancy implies opportunities to streamline model architectures, reduce computational and deployment costs, and improve interpretability by pruning inactive or duplicative attention components.
Organizations developing or deploying language models should leverage attention map analysis as a standard diagnostic tool alongside vector evaluations to audit model capabilities. Model optimization teams should explore pruning redundant heads to reduce runtime latency while preserving specialized linguistic heads. Future research should evaluate whether these attention patterns persist across larger architectures and diverse languages, and explore methods to deliberately train compact models with specialized attention distributions.
Confidence in these findings is high for standard English language benchmarks under the BERT-base architecture. However, limitations remain: the quantitative linguistic evaluations were restricted to English datasets with truncated sequence lengths of 128 tokens, and individual heads showed high proficiency only on specific grammatical relations rather than full-sentence parsing independently. Stakeholders should account for these boundary conditions when generalizing the findings to other languages or longer-context models.
- Paper: BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding, Jacob Devlin et al. (2019). Introduces the bidirectional Transformer architecture and pre-training objectives of BERT, which serves as the direct subject of analysis in this paper.
- Paper: Attention is not Explanation, Sarthak Jain et al. (2019). Establishes foundational methodology and critical skepticism regarding whether attention weights faithfully reflect linguistic and model explanations.
- Paper: Head-Driven Statistical Models for Natural Language Parsing, Michael Collins (2003). Provides the foundational syntactic head-modifier parsing theory against which individual BERT attention heads are evaluated.
- Paper: Deep contextualized word representations, Matthew E. Peters et al. (2018). Pioneered the analysis and extraction of contextualized linguistic representations across deep neural network layers.
- Paper: BERT Rediscovers the Classical NLP Pipeline, Ian Tenney et al. (2019). Extends the linguistic analysis of BERT by investigating how its layered representations systematically encode the classical NLP pipeline.
- Paper: DeBERTa: Decoding-enhanced BERT with Disentangled Attention, Pengcheng He et al. (2021). Builds on insights into BERT's attention limitations by introducing disentangled attention mechanisms that separately compute content and relative position.
- Paper: SpanBERT: Improving Pre-training by Representing and Predicting Spans, Mandar Joshi et al. (2019). Improves upon BERT's token-level attention and representations by pre-training directly on contiguous text spans.
- Paper: RoBERTa: A Robustly Optimized BERT Pretraining Approach, Yinhan Liu et al. (2019). Presents a rigorous optimization study of BERT's pre-training design and hyperparameter space based on early BERT analysis.
- Paper: Synthesizer: Rethinking Self-Attention for Transformer Models, Yi Tay et al. (2021). Critically re-evaluates the necessity of dot-product self-attention patterns in Transformers by testing synthetic and alignment-free alternatives.
- Paper: Language Models as Knowledge Bases?, Fabio Petroni et al. (2019). Examines whether pre-trained models like BERT store factual and relational knowledge directly in their representations.
- Paper: On the Relationship between Self-Attention and Convolutional Layers, Jean-Baptiste Cordonnier et al. (2020). Analyzes the theoretical and empirical behavior of multi-head self-attention mechanisms in relation to convolutional operations.
