SANVis: Visual Analytics for Understanding Self-Attention Networks

Cheonbok Park, Jaegul Choo, Inyoup Na, Yongjang Jo, Sungbok Shin, Jaehyo Yoo, Bum Chul Kwon, Jian Zhao, Hyungjong Noh, Yeonsoo Lee

Introduction

The Transformer architecture and its multi-head self-attention mechanism have revolutionized Natural Language Processing (NLP). Despite their state-of-the-art performance, these models remain "black boxes" due to their immense complexity. A single model may contain dozens of layers and hundreds of attention heads, making it difficult for researchers to discern whether a head has learned meaningful linguistic structures or is merely processing noise. SANVis is a visual analytics system designed to address this interpretability gap by providing interactive, multi-scale explorations of self-attention behaviors.

System Architecture

SANVis operates on two primary scales: a macro-level Network View and a micro-level HeadLens.

The Network View (Macro-level)

The Network View visualizes the global flow of information across Transformer layers. It employs several techniques to manage complexity:

  • Sankey Diagrams: These visualize the transfer of attention weights between words across successive layers, highlighting how information is aggregated.
  • Attention Sorting: To identify functional patterns, users can sort heads by entropy (measuring focus) or positional offset (measuring relative distance between query and key words).
  • Attention Piling: This feature uses hierarchical clustering to group heads with similar attention patterns into "piles," reducing visual clutter and allowing researchers to identify common behavioral archetypes across the entire network.
The SANVis interface, featuring the multi-scale Network View (A) and the granular HeadLens (B).

The HeadLens (Micro-level)

When a specific head of interest is identified, the HeadLens provides a deep dive into its internal representations. It applies K-means++ clustering to Query and Key vectors to find representative word groups. By integrating Part-of-Speech (POS) tagging and word clouds, it reveals the linguistic profiles of these clusters, such as a head that consistently attends to nouns when querying auxiliary verbs.

Experimental Evaluation

The authors evaluated SANVis using a Transformer model trained on an English-French translation task using TED lecture scripts (WMT benchmark). The model achieved a BLEU score of 38.4, ensuring that the visualizations reflect a high-performing, representative system.

Analysis of Attention Patterns

The tool reveals that attention heads are highly specialized rather than redundant. By examining heatmaps, researchers can visually confirm linguistic alignment; for example, diagonal patterns in encoder-decoder attention signify the model's mastery of word-order mapping between languages.

Small multiples of attention heatmaps demonstrating the diverse specialization of individual heads.

Through the HeadLens, the authors discovered "functional" heads that act as syntactic filters. One specific example, Head 7 in Layer 4, was found to capture the relationship between auxiliary verbs (e.g., "is", "are") and nouns (e.g., "world", "life"), demonstrating that the model captures genuine grammatical dependencies.

Conclusion and Future Work

SANVis successfully demystifies the internal mechanics of Transformers by providing tools for both high-level pattern recognition and low-level linguistic profiling. While the current system focuses on Query and Key vectors, future iterations aim to incorporate Value vectors to provide a complete picture of the attention transformation. Additionally, the authors plan to extend the system to large-scale pre-trained models like BERT and conduct extensive user studies to further refine the interface for deep learning practitioners.

Summary updated

BibTeX
@inproceedings{park2019sanvis,
  author = {Cheonbok Park and Jaegul Choo and Inyoup Na and Yongjang Jo and Sungbok Shin and Jaehyo Yoo and Bum Chul Kwon and Jian Zhao and Hyungjong Noh and Yeonsoo Lee},
  title = {{SANVis: Visual Analytics for Understanding Self-Attention Networks}},
  booktitle = {IEEE VIS (Short Papers)},
  year = {2019},
  url = {https://openreview.net/forum?id=1rpQlcFaYrY},
}
Figure