Abstract
Vision transformer (ViT) expands the success of transformer models from sequential data to images. The model decomposes an image into many smaller patches and arranges them into a sequence. Multi-head self-attentions are then applied to the sequence to learn the attention between patches. Despite many successful interpretations of transformers on sequential data, little effort has been devoted to the interpretation of ViTs, and many questions remain unanswered. In this work, we answer these questions through a visual analytics approach. Specifically, we first identify what heads are more important in ViTs by introducing multiple pruning-based metrics. Then, we profile the spatial distribution of attention strengths between patches inside individual heads, as well as the trend of attention strengths across attention layers. Third, using an autoencoder-based learning solution, we summarize all possible attention patterns that individual heads could learn. Examining the attention strengths and patterns of the important heads, we answer why they are important. Through concrete case studies with experienced deep learning experts on multiple ViTs, we validate the effectiveness of our solution that deepens the understanding of ViTs from head importance, head attention strength, and head attention pattern.
Introduction
While Vision Transformers (ViTs) have reached state-of-the-art performance in computer vision, their inner workings remain opaque. Unlike their predecessors, Convolutional Neural Networks (CNNs), which have well-understood hierarchical feature extractors (edges → shapes → objects), ViTs rely on multi-head self-attention. This architecture presents three major challenges for interpretation: identifying critical vs. redundant heads, tracking spatial context in flattened 1D sequences, and categorizing the diversity of learned attention patterns.
Methodology: The Three Pillars of ViT Interpretation
To address these challenges, the authors developed a coordinated visual analytics system based on three novel analytical pillars:
- Multi-Perspective Head Importance: Using "leave-one-out" pruning (ablation) to measure a head's impact. The framework distinguishes between model-level impact (final class probability changes) and layer-level impact (internal activation changes), helping identify "stepping stone" heads vital for internal representations.
- $k$-Hop Attention Strength: To capture 2D spatial behavior, the system profiles how much a patch attends to its neighbors at different distances ($k$-hops). Entropy metrics determine if a head is "local" (immediate neighbors) or "global" (image-wide).
- Unsupervised Pattern Discovery: An Autoencoder (AE) was trained on binarized attention matrices to cluster latent representations, automatically identifying recurring attention "motifs" across thousands of images.
The Visual Analytics Dashboard
These metrics are integrated into an interactive dashboard featuring an "Image Overview" (using t-SNE to cluster images by head importance), a "Head Importance View," and an "Attention Pattern View." This allows researchers to drill down from global model behavior to the specific spatial attention of a single head on a single image.
Key Insights and Results
- Content-Agnostic vs. Content-Relevant: Lower-layer heads often follow fixed, "content-agnostic" heuristics (e.g., always attending to the patch below). Higher-layer heads are "content-relevant," focusing on specific semantic objects like a bird's wing or a cat's face.
- The 13 Patterns: Unsupervised clustering revealed 13 distinct attention patterns, categorized into four base types: diagonal (self/neighbor), horizontal, vertical, and block (local regions).
- CLS Token Evolution: The "class" (CLS) token starts by attending to itself in early layers and gradually shifts to "collecting" information from semantically important patches in later layers.
- Expert Validation: Seven deep learning experts confirmed that linking importance to specific spatial patterns (e.g., object boundary extraction) provided insights that traditional tools could not.
Conclusion and Future Work
While this framework provides a systematic way to "open the black box" of ViTs, limitations remain. Current pruning does not account for complex head dependencies, and the analysis focuses on classification rather than generative or detection tasks. Future work will explore attention "flow" across layers and extend the analytics to models like Stable Diffusion.
Summary updated