[Paper Review] Visualizing Attention in Transformer-Based Language Representation Models
This paper presents an open-source tool to visualize multi-head self-attention in Transformer models, with three views (attention-head, model, neuron) demonstrated on GPT-2 and BERT, plus use cases for bias detection and pattern analysis.
We present an open-source tool for visualizing multi-head self-attention in Transformer-based language representation models. The tool extends earlier work by visualizing attention at three levels of granularity: the attention-head level, the model level, and the neuron level. We describe how each of these views can help to interpret the model, and we demonstrate the tool on the BERT model and the OpenAI GPT-2 model. We also present three use cases for analyzing GPT-2: detecting model bias, identifying recurring patterns, and linking neurons to model behavior.
Motivation & Objective
- Introduce an open-source visualization tool for Transformer self-attention.
- Extend prior visualization work to encoder-only and decoder-only models (BERT and GPT-2).
- Provide three views (attention-head, model, neuron) to interpret attention and model behavior.
- Demonstrate use cases on GPT-2 for bias detection, recurring patterns, and linking neurons to behavior.
Proposed method
- Adapt the Tensor2Tensor-style attention visualization to GPT-2 and BERT architectures.
- Implement three views: attention-head view, model view, and neuron view.
- Visualize attention as token-to-token connections with color-coded heads and weighted lines.
- Expose neuron-level traces of queries and keys to show how attention is computed (q, k, q×k, q·k, Softmax).
- Provide interactive filtering by layer, head, and sentences to reveal patterns and potential biases.
Experimental results
Research questions
- RQ1How can multi-head self-attention in GPT-2 and BERT be effectively visualized across different granularities?
- RQ2What patterns and biases can be identified through attention visualizations in transformer models?
- RQ3Can neuron-level inspection reveal links between individual neurons and attention behavior?
- RQ4Does visualization help explain recurring attention patterns and potential null or distance-based attention?
Key findings
- The tool enables visualization of attention patterns at head, model, and neuron granularity for GPT-2 and BERT.
- Attention heads show lexical patterns, coreference-like behavior, and sentence-pair interactions in BERT and GPT-2.
- Model view reveals recurring patterns such as null attention predominantly focusing on the first token.
- Neuron view traces how specific neurons contribute to attention through q, k, and their products, enabling potential manipulation to alter behavior.
- Use cases illustrate potential bias detection, recurring attention patterns, and linking neurons to model behavior.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.