# What Does BERT Look At? An Analysis of BERT's Attention

Attention maps reveal which words BERT's heads track and how

Kevin Clark, Urvashi Khandelwal, Omer Levy, Christopher D. Manning · arXiv · 2019-6-11

- **Problem** Earlier BERT analyses read model outputs or internal vectors, not attention maps. Attention shows how much each word contributes to another word's representation, so it is easier to read.
- **Method** The authors treat each attention head as a classifier. Each head predicts a word's head by naming the word it attends to most, with no training.
- **Results** Head 8-10 scored 86.8 on dobj, compared to 40.0 for its fixed-offset baseline. Other heads also track determiners, prepositions and coreference.

## Why attention is worth probing

Large pre-trained models such as BERT perform very well after fine-tuning, yet the reason is still not well understood. Earlier studies examined the model's outputs on carefully chosen sentences, or its internal vectors through probing classifiers. Attention is easier to read than those signals, because each weight says how much one word contributes to the next representation of another word.

The authors therefore study the attention maps of a pre-trained model, using BERT as the test case.

The analysis covers the 144 attention heads of BERT-base, which has 12 layers with 12 heads each. BERT-base is a large Transformer that the authors chose because it performs strongly on many tasks.

## Recurring surface patterns in attention

The authors extracted attention maps from BERT-base over 1000 random Wikipedia segments. Each segment holds at most 128 tokens, made of two consecutive paragraphs and arranged in the BERT input format with \[CLS\] and \[SEP\] tokens. Across these maps, some heads attend to delimiter tokens, some to fixed positional offsets, and some broadly over the whole sentence.

Heads in the same layer often behave alike, which is the first sign that layers have a shared character.

The most striking pattern is how much attention lands on special tokens. Over half of BERT's attention in layers 6 to 10 falls on \[SEP\]. Early heads favor \[CLS\], middle heads favor \[SEP\], and deep heads favor periods and commas. A uniform spread would give a token that appears twice in a segment only about 1/64 of the attention.

One guess is that \[SEP\] collects segment-level information that other heads read later. The authors doubt this, because heads that process \[SEP\] put more than 90% of their attention on themselves and on other \[SEP\] tokens. Instead, they propose a no-op reading: when a head's function doesn't apply to the current token, it parks its attention on a special token.

A similar pattern appears for the uncased BERT model, which suggests the effect is systematic rather than random training noise.

To test the no-op reading, the authors compute the magnitude of the gradient of the masked language modeling loss with respect to each attention weight. Starting in layer 5, the gradients for attention to \[SEP\] become very small. Changing attention to \[SEP\] therefore doesn't change BERT's outputs much, which supports the no-op reading. This rests on gradient measurements and a functional analysis, so the authors present it as a hypothesis rather than a proven mechanism.

Entropy measures how focused a head's attention is, and some lower-layer heads spread their attention very broadly. These heads spend at most 10% of their attention on any single word, so their output is roughly a bag-of-vectors representation. Attention from \[CLS\] in the last layer has an entropy of 3.89 nats, which the authors attribute to \[CLS\] feeding the next sentence prediction task.

## Single heads as word-level classifiers

Each head predicts the head of a word by naming the other word it attends to most, with no training involved. BERT splits some words into several byte-pair tokens, about 8% of the words in the data, so token attention has to be converted to word attention. Attention to a split word is summed over its tokens, and attention from a split word is averaged over them.

These conversions keep the attention from each word summing to 1, and \[SEP\] and \[CLS\] are ignored when picking the prediction.

The authors run this on the WSJ portion of the Penn Treebank, annotated with Stanford Dependencies. They score both directions of each head-dependent pair, and they compare against a fixed-offset baseline, since some relations are easy to predict by position. No single head does well overall, because the best head reaches 34.5 UAS while the right-branching baseline reaches 26.3 UAS.

The gains come instead from specific relations, which is why the authors look at relations one at a time.

Head 9-6 handles prepositions and their objects, reaching 76.3 on pobj against 34.6 for the best offset baseline. Head 8-11 attends from noun modifiers to their nouns, scoring 94.3 on det compared to 51.7 for its baseline. Head 8-10 links direct objects to their verbs, scoring 86.8 on dobj compared to 40.0 for its baseline.

The authors explain this by noting that each dependent has exactly one head, while a head can have many dependents. They read such disagreements as evidence that these behaviors arise from self-supervised training rather than from copying a human design.

## Coreference results for one head

The authors evaluate heads on coreference with the CoNLL-2012 dataset, which is harder for attention because coreference links tend to be longer than syntactic dependencies. The score is antecedent selection accuracy: how often the head word of a mention attends most to the head word of one of its antecedents. They compare this against three baselines: the nearest other mention, the nearest mention with the same head word, and a rule-based system with four sieves.

Documents were truncated to 128 tokens to keep memory usage manageable.

Head 5-4 scores 65 overall, compared to 52 for the head-match baseline and 69 for the rule-based system. On nominal mentions it scores 58, compared to 40 for head match and 60 for the rule-based system. The authors note that the head is especially good with nominal mentions, possibly because it matches synonyms in a fuzzy way. The neural coreference system scores 83, but the authors caution that this comparison is only rough because of truncation and different mention detection.

## Combining heads in a trained probe

Individual heads each cover some relations, so the authors ask how much syntax all heads hold together. They train a small probe on fixed BERT attention outputs, so only a few parameters are learned and BERT is not updated. The Attention-Only Probe scores a candidate head j for a word i with the weighted sum of attention from i to j and from j to i across all heads.

The weights w and u are learned from the training set, and the score is turned into a probability over the words in the sentence.

The Attention-and-Words Probe lets the head weights depend on the words, by concatenating the GloVe vectors of the dependent and the candidate head. The GloVe vectors stay fixed, so only the matrices W and U are trained, and the weight for head k becomes word-sensitive. For example, for the pair 'the' and 'cat' the probe should put most of its weight on head 8-11, which handles determiners well.

The probes are evaluated on the Penn Treebank development set with Stanford Dependencies, and they are compared with three baselines. The Attn + GloVe probe reaches 77 UAS, compared to 58 for Distances + GloVe, 61 for the attention-only probe, 30 for randomly initialized attention, and 26 for right-branching. The authors read this as attention maps holding a fairly thorough picture of English syntax.

The structural probe of Hewitt and Manning reaches 80 UUAS, but it uses a single BERT layer, undirected trees and distances rather than direct parses. So the two scores aren't directly comparable, though they are close enough to suggest that BERT's vectors hold little more syntax than its attention maps.

## How similar heads are within a layer

The authors measure the distance between two heads as the sum, over all tokens, of the Jensen-Shannon divergence between their attention distributions. They then embed the heads in two dimensions with multidimensional scaling, so that Euclidean distances approximate these divergences as closely as possible. The resulting map shows several clear clusters, and heads in the same layer tend to sit close together.

This is somewhat surprising, because Tu et al. show that pushing attention heads apart can improve Transformer translation. The authors suggest that attention dropout, which zeroes some attention weights during training, may explain part of the redundancy.

## Limitations

Individual heads capture dependency structure only for some relations, and for many relations BERT improves only slightly over the simple baseline. So the authors don't claim that single heads capture dependency structure as a whole. The analysis was done on English only, and the authors leave other languages to future work.

The analysis found interpretable behavior in only a subset of BERT's attention heads. Pruning studies suggest the remaining heads may have little effect on performance, so the uninterpreted heads may simply matter less. Coreference rests on a single head and truncated documents, so it is a narrower result than the syntax analysis.

Jain and Wallace argue that attention often doesn't explain predictions, but the authors look at attention to learn what the model has learned rather than to explain outputs.

## Paper info

- **Authors**: Kevin Clark, Urvashi Khandelwal, Omer Levy, Christopher D. Manning
- **Venue**: arXiv · Preprint
- **First published**: 2019-6-11
- **Added**: 2026-11-12
- **Updated**: 2019-6-11
- **Version**: v1
- **arXiv**: 1906.04341
- **Category**: cs.CL
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1906.04341v1) · [PDF ↗](https://arxiv.org/pdf/1906.04341v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Kevin Clark, Urvashi Khandelwal, Omer Levy, Christopher D. Manning (2019). What Does BERT Look At? An Analysis of BERT's Attention. arXiv:1906.04341v1. https://arxiv.org/abs/1906.04341v1

**BibTeX**

```
@misc{clark2019what,
  title = {{What Does BERT Look At? An Analysis of BERT's Attention}},
  author = {Kevin Clark and Urvashi Khandelwal and Omer Levy and Christopher D. Manning},
  year = {2019},
  eprint = {1906.04341},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1906.04341v1}
}
```

## Other paper commentary

- [AutoPrompt: Eliciting Knowledge from Language Models with Automatically Generated Prompts](https://refivu.com/en/papers/e3fa3b73-5b1d-4ff0-8f81-98fad2340fa5-autoprompt-eliciting-knowledge-from-language-models-with.md)
- [DeepSeek-Coder: When the Large Language Model Meets Programming -- The Rise of Code Intelligence](https://refivu.com/en/papers/a9b5666a-9125-4553-968a-b6f76e0d19db-deepseek-coder-when-the-large-language-model-meets.md)
- [OpenAI GPT-5 System Card](https://refivu.com/en/papers/678bc558-0d7f-4ee8-9fa0-55c5eb2daf22-openai-gpt-5-system-card.md)
- [Siren's Song in the AI Ocean: A Survey on Hallucination in Large Language Models](https://refivu.com/en/papers/b7a8b2ba-0d8c-47b1-8619-757da5d13fc9-siren-s-song-in-the-ai-ocean-a.md)
- [Conditional Prompt Learning for Vision-Language Models](https://refivu.com/en/papers/aafdc9ad-313a-44a6-bed9-42556a8097ea-conditional-prompt-learning-for-vision-language-models.md)
- [Federated Learning for Mobile Keyboard Prediction](https://refivu.com/en/papers/e56197ce-a521-4965-9369-f978e10dc5fe-federated-learning-for-mobile-keyboard-prediction.md)
- [InstructPix2Pix: Learning to Follow Image Editing Instructions](https://refivu.com/en/papers/b87997ee-e5f2-4a2e-9b66-e15df3a71be7-instructpix2pix-learning-to-follow-image-editing.md)
- [MemNet: A Persistent Memory Network for Image Restoration](https://refivu.com/en/papers/80fb0022-b1b0-497f-8285-0c27e8c156fc-memnet-a-persistent-memory-network-for-image-restoration.md)
- [Unsupervised Learning of Video Representations using LSTMs](https://refivu.com/en/papers/a715f01b-843f-4405-90d9-dbb255bc47c5-unsupervised-learning-of-video-representations-using-lstms.md)
- [Curiosity-driven Exploration by Self-supervised Prediction](https://refivu.com/en/papers/93936438-d2c7-4a12-b814-3073185546ca-curiosity-driven-exploration-by-self-supervised-prediction.md)
- [FFA-Net: Feature Fusion Attention Network for Single Image Dehazing](https://refivu.com/en/papers/05326df3-34c3-4503-97d2-d46822e1fbfa-ffa-net-feature-fusion-attention-network-for-single.md)
- [Expressive Body Capture: 3D Hands, Face, and Body from a Single Image](https://refivu.com/en/papers/13b094cd-136a-43d9-a552-fafa9aa19691-expressive-body-capture-3d-hands-face-and-body.md)

## Terms in this paper

- [Accuracy](https://refivu.com/en/terms/1995c0cd6282-accuracy)
- [Transformer](https://refivu.com/en/terms/48e8be2570bc-transformer)
- [masked language modeling](https://refivu.com/en/terms/5df1a60d4f18-masked-language-modeling)
- [Penn Treebank](https://refivu.com/en/terms/fffc021679a8-penn-treebank)
- [Coreference resolution](https://refivu.com/en/terms/833bc9442de4-coreference-resolution)
- [Jensen-Shannon divergence](https://refivu.com/en/terms/408b4685369b-jensen-shannon-divergence)
- [Dependency Parsing](https://refivu.com/en/terms/aa61b2aab01e-dependency-parsing)
- [entropy](https://refivu.com/en/terms/4c6413bc6b11-entropy)
- [CoNLL-2012](https://refivu.com/en/terms/ae7d42cfcbe2-conll-2012)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/8f682775-2bc4-4c36-a7e8-6afc56d2aeae-what-does-bert-look-at-an-analysis-of)
