[Paper Review] What do Vision Transformers Learn? A Visual Exploration
This paper visualizes Vision Transformers (ViTs) to understand what they learn, showing that ViTs trained with language supervision respond to semantic concepts, preserve spatial information up to the last layer, and rely more on background cues than CNNs, with last-layer token mixing acting like learned pooling.
Vision transformers (ViTs) are quickly becoming the de-facto architecture for computer vision, yet we understand very little about why they work and what they learn. While existing studies visually analyze the mechanisms of convolutional neural networks, an analogous exploration of ViTs remains challenging. In this paper, we first address the obstacles to performing visualizations on ViTs. Assisted by these solutions, we observe that neurons in ViTs trained with language model supervision (e.g., CLIP) are activated by semantic concepts rather than visual features. We also explore the underlying differences between ViTs and CNNs, and we find that transformers detect image background features, just like their convolutional counterparts, but their predictions depend far less on high-frequency information. On the other hand, both architecture types behave similarly in the way features progress from abstract patterns in early layers to concrete objects in late layers. In addition, we show that ViTs maintain spatial information in all layers except the final layer. In contrast to previous works, we show that the last layer most likely discards the spatial information and behaves as a learned global pooling operation. Finally, we conduct large-scale visualizations on a wide range of ViT variants, including DeiT, CoaT, ConViT, PiT, Swin, and Twin, to validate the effectiveness of our method.
Motivation & Objective
- Investigate what ViTs learn through improved feature visualization techniques.
- Compare ViTs to CNNs in terms of spatial information maintenance and reliance on background vs foreground cues.
- Assess how language-supervised ViTs (e.g., CLIP) differ in feature representations from standard image-classification ViTs.
- Examine how the last layer of ViTs globalizes information and how spatial information persists across layers.
Proposed method
- Develop a gradient-based activation maximization framework tailored for ViTs, enabling interpretable visualizations of high-dimensional feed-forward features.
- Visualize and compare keys, queries, values, and feed-forward outputs to assess interpretability across layers.
- Use augmentation ensembling, total-variation regularization, and specific image augmentations (Jitter, ColorShift, Gaussian smoothing) to improve visualization quality.
- Analyze patch-wise activation maps to assess spatial information preservation and behavior of CLS vs. non-CLS tokens.
- Conduct large-scale visualizations across ViT variants (ViT-B16, DeiT, CoaT, ConViT, PiT, Swin, Twin) to validate method robustness.
Experimental results
Research questions
- RQ1How do ViTs visualize and interpret their internal representations across layers?
- RQ2Do ViTs preserve spatial information at the patch level, and how does this change in the last layer?
- RQ3How does the last ViT layer mix tokens, and is this akin to pooling or globalization?
- RQ4How do ViTs compare to CNNs in using background vs foreground information for classification?
- RQ5What are the effects of language supervision (CLIP) on ViT feature representations?
Key findings
- Feed-forward representations in ViTs yield the most interpretable visualizations, while attention components (keys/queries/values) are harder to interpret due to high-dimensional, multi-modal-like coding.
- Patch-wise activation maps in ViTs often resemble saliency maps and preserve patch-level spatial relationships across layers, except in the final layer.
- The last ViT layer performs token mixing similar to average pooling, enabling a global information aggregation for the CLS token (and even when applied to individual patches).
- ViTs tend to use background information more effectively than CNNs for correct class identification, and their performance degrades less when background is removed; however, CNNs rely more on high-frequency texture information.
- CLIP-trained ViTs exhibit semantic and conceptual features (e.g., morbid concepts, music-related concepts) beyond simple object detectors, reflecting language supervision shaping representations.
- ViTs retain spatial information throughout layers and show a progression from textures to parts to objects analogous to CNNs, with language supervision pushing toward abstract concepts.
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.