Skip to main content
QUICK REVIEW

[Paper Review] Analyzing Vision Transformers for Image Classification in Class Embedding Space

Martina G. Vilas, Schaumlöffel, Timothy|arXiv (Cornell University)|Oct 29, 2023
Explainable Artificial Intelligence (XAI)Computer Science7 citations
TL;DR

This paper introduces a novel framework to interpret Vision Transformers (ViTs) by projecting intermediate hidden states onto the learned class embedding space, revealing how image tokens progressively align with class prototypes through attention and MLP mechanisms. The method enables efficient, accurate identification of salient image regions for classification and outperforms linear probing in capturing task-relevant features.

ABSTRACT

Despite the growing use of transformer models in computer vision, a mechanistic understanding of these networks is still needed. This work introduces a method to reverse-engineer Vision Transformers trained to solve image classification tasks. Inspired by previous research in NLP, we demonstrate how the inner representations at any level of the hierarchy can be projected onto the learned class embedding space to uncover how these networks build categorical representations for their predictions. We use our framework to show how image tokens develop class-specific representations that depend on attention mechanisms and contextual information, and give insights on how self-attention and MLP layers differentially contribute to this categorical composition. We additionally demonstrate that this method (1) can be used to determine the parts of an image that would be important for detecting the class of interest, and (2) exhibits significant advantages over traditional linear probing approaches. Taken together, our results position our proposed framework as a powerful tool for mechanistic interpretability and explainability research.

Motivation & Objective

  • To develop a method for interpreting how Vision Transformers build categorical representations during image classification.
  • To understand the roles of self-attention and MLP layers in forming class-specific representations.
  • To identify image regions most relevant to class prediction using a unified, efficient framework.
  • To demonstrate advantages over traditional linear probing in capturing task-relevant features.
  • To enable mechanistic interpretability without optimization, providing human-interpretable insights into ViT internals.

Proposed method

  • Project hidden states of image tokens at any layer onto the class embedding space using the output projection matrix.
  • Utilize the pre-trained class embedding matrix as a reference space to quantify alignment of internal representations with class prototypes.
  • Apply positive and negative token perturbation experiments to assess the importance of image regions for classification.
  • Compare the framework’s performance with linear probing by measuring model accuracy after removing low-scoring tokens.
  • Use key-value memory pair mechanisms in self-attention to analyze how attention dynamics contribute to categorical representation formation.
  • Leverage one forward pass on validation data to compute interpretability scores, avoiding costly training of additional classifiers.
Figure 1: Schematic of our framework. (a) The hidden states of image tokens $x_{n}$ in a block $b$ are projected onto the class embedding space using the output embedding matrix $\mathbf{E}$ . (b) A key-value memory pair system in a self-attention layer. Key vectors $k_{j}$ belong to different atten
Figure 1: Schematic of our framework. (a) The hidden states of image tokens $x_{n}$ in a block $b$ are projected onto the class embedding space using the output embedding matrix $\mathbf{E}$ . (b) A key-value memory pair system in a self-attention layer. Key vectors $k_{j}$ belong to different atten

Experimental results

Research questions

  • RQ1How do image tokens in Vision Transformers progressively align with learned class prototypes during inference?
  • RQ2What roles do self-attention and MLP layers play in constructing categorical representations?
  • RQ3Can the class embedding space projection method identify the most informative image regions for classification?
  • RQ4How does this framework compare to linear probing in capturing features relevant to model decisions?
  • RQ5To what extent do attention mechanisms and contextual information influence the development of class-specific representations?

Key findings

  • Image tokens develop class-specific representations early in the ViT hierarchy, with increasing alignment to class prototypes through self-attention and MLP layers.
  • The framework identifies image regions critical for classification, with performance maintained even after removing up to 60% of the least important tokens.
  • Positive and negative perturbation experiments show significantly higher AUC for the proposed method compared to random removal, confirming its predictive power.
  • The method outperforms linear probing in identifying task-relevant features, as linear probes often decode separable but irrelevant representations.
  • The framework is more time-efficient than linear probing, requiring only one forward pass instead of multiple training steps per layer.
  • Key-value memory pair mechanisms in self-attention are shown to differentially contribute to categorical representation formation, with distinct roles for attention and MLP components.
Figure 2: Evolution of class identifiability mean scores across normalized blocks.
Figure 2: Evolution of class identifiability mean scores across normalized blocks.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.