Quantifying Attention Flow in Transformers

Samira Abnar, Willem Zuidema
5/2/2020
cs.LGcs.AIcs.CL

Official code: samiraabnar/attention_flow (275 stars, last commit 2021-09-09).

Abstract

In the Transformer model, "self-attention" combines information from attended embeddings into the representation of the focal embedding in the next layer. Thus, across layers of the Transformer, information originating from different tokens gets increasingly mixed. This makes attention weights unreliable as explanations probes. In this paper, we consider the problem of quantifying this flow of information through self-attention. We propose two methods for approximating the attention to input tokens given attention weights, attention rollout and attention flow, as post hoc methods when we use attention weights as the relative relevance of the input tokens. We show that these methods give complementary views on the flow of information, and compared to raw attention, both yield higher correlations with importance scores of input tokens obtained using an ablation method and input gradients.

View on arXivView PDF

Code Implementations(1)

27537Python, Jupyter NotebookApr 22, 20205 years ago

Similar Papers

Cite this paper

@article{abnar2020quantifying,
  title  = {Quantifying Attention Flow in Transformers},
  author = {Samira Abnar and Willem Zuidema},
  year   = {2020},
  eprint = {2005.00928},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2005.00928}
}

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/2005.00928.svg)](https://codeofpaper.com/paper/2005.00928)

Discussion