A Multiscale Visualization of Attention in the Transformer Model

Jesse Vig
6/12/2019
cs.HCcs.CLcs.LG

Official code: jessevig/bertviz (8,201 stars, Apache-2.0, PyTorch, last commit 2026-01-08).

Abstract

The Transformer is a sequence model that forgoes traditional recurrent architectures in favor of a fully attention-based approach. Besides improving performance, an advantage of using attention is that it can also help to interpret a model by showing how the model assigns weight to different input elements. However, the multi-layer, multi-head attention mechanism in the Transformer model can be difficult to decipher. To make the model more accessible, we introduce an open-source tool that visualizes attention at multiple scales, each of which provides a unique perspective on the attention mechanism. We demonstrate the tool on BERT and OpenAI GPT-2 and present three example use cases: detecting model bias, locating relevant attention heads, and linking neurons to model behavior.

View on arXivView PDF

Code Implementations(1)

jessevig/bertvizOfficial100%
PyTorchApache-2.0

BertViz: Visualize Attention in Transformer Models

8,201887Python, JavaScriptDec 16, 20189 months agoApache-2.0
bertgpt2machine-learningnatural-language-processingneural-network+6 more

Similar Papers

Cite this paper

@article{vig2019multiscale,
  title  = {A Multiscale Visualization of Attention in the Transformer Model},
  author = {Jesse Vig},
  year   = {2019},
  eprint = {1906.05714},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/1906.05714}
}

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

Discussion