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

Kevin Clark, Urvashi Khandelwal, Omer Levy, Christopher D. Manning
6/11/2019
2,252 citations
cs.CL
transformer-attention

Official code: clarkkev/attention-analysis (475 stars, Jupyter Notebook, MIT, last commit 2021-04-04).

Abstract

Large pre-trained neural networks such as BERT have had great recent success in NLP, motivating a growing body of research investigating what aspects of language they are able to learn from unlabeled data. Most recent analysis has focused on model outputs (e.g., language model surprisal) or internal vector representations (e.g., probing classifiers).

Show full abstract

Complementary to these works, we propose methods for analyzing the attention mechanisms of pre-trained models and apply them to BERT. BERT's attention heads exhibit patterns such as attending to delimiter tokens, specific positional offsets, or broadly attending over the whole sentence, with heads in the same layer often exhibiting similar behaviors. We further show that certain attention heads correspond well to linguistic notions of syntax and coreference. For example, we find heads that attend to the direct objects of verbs, determiners of nouns, objects of prepositions, and coreferent mentions with remarkably high accuracy. Lastly, we propose an attention-based probing classifier and use it to further demonstrate that substantial syntactic information is captured in BERT's attention.

View on arXivView PDF

Code Implementations(1)

MIT
47582Jupyter Notebook, PythonJun 7, 20195 years agoMIT

Similar Papers

Cite this paper

@article{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.04341}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1906.04341.svg)](https://codeofpaper.com/paper/1906.04341)

Discussion