ViT-CX: Causal Explanation of Vision Transformers

Weiyan Xie, Xiao-Hui Li, Caleb Chen Cao, Nevin L. Zhang

TL;DR

ViT-CX is a new explanation method for Vision Transformers (ViTs) that moves away from noisy attention weights to focus on the causal impact of semantic patch embeddings. By addressing ViT-specific quirks like causal overdetermination and mask artifacts, it produces saliency maps that are significantly more faithful to the model and intuitive for human users.

What Problem Does This Paper Address?

As Vision Transformers (ViTs) become the standard for computer vision, understanding why they make specific predictions is crucial. Most current eXplainable AI (XAI) methods for ViTs rely on attention weights—specifically how much the [CLS] token "attends" to various image patches.

However, the authors argue that attention weights are a poor proxy for importance. They represent the relationship between tokens, not necessarily the semantic content of the patches themselves. Furthermore, simply porting successful CNN-based methods like Score-CAM to ViTs fails because ViTs behave differently. They are highly robust to missing data (causal overdetermination) and have a strong ability to recognize shapes even when pixels are masked, which can lead to "artifact bias" where the model makes a prediction based on the shape of the mask rather than the image content.

Figure 1: Explaining the predictions of ViT-B/16 on four images. The saliency maps by ViT-CX are clearly more meaningful than those by previous attention-based methods (CGW1, CGW2, TAM), highlighting all regions apparently important to predictions. They are also more faithful to the model as measured by the deletion (Del) and insertion (Ins) AUC metrics. In contrast, the direct application of Score-CAM to ViTs can lead to nonsensical explanations (e.g., the goldfish and head cabbage example).

Methods

ViT-CX operates in two main phases: Mask Generation and Mask Aggregation.

  1. Mask Generation: Instead of looking at attention, ViT-CX extracts patch embeddings from a transformer block and reshapes them into a 3D tensor. Frontal slices of this tensor are upsampled to create "feature maps." Because ViT feature maps are highly redundant (unlike CNNs), the authors use agglomerative clustering to merge similar masks, reducing the number of masks from hundreds down to about 70 on average. This drastically improves computational efficiency.
  2. Mask Aggregation: To create the final saliency map, the masks are applied to the input image, and the model's output score is recorded. To solve the "artifact bias," the authors add random Gaussian noise to the masked-out areas. This prevents the ViT from using the silhouette of the mask to identify the object.
  3. PCB Correction: Finally, they apply a Pixel Coverage Bias (PCB) correction. In models with high "causal overdetermination" (where many different small patches can trigger a correct prediction), standard methods tend to highlight pixels simply because they appear in more masks. ViT-CX divides the saliency value by the frequency of pixel coverage to ensure the map reflects true causal impact.
Figure 3: Overview of ViT-CX. (a) Mask Generation: A set of semantic masks is generated from the patch embeddings with agglomerative clustering. (b) Mask Aggregation: A saliency map is created by combining the masks using a debiased causal impact score based on the masked image with randomness to overcome artifacts. Pixel coverage frequencies are used in this step to correct pixel coverage bias.

Datasets

The researchers evaluated ViT-CX using:

  • ImageNet (ILSVRC2012): Specifically, a subset of 5,000 randomly selected images from the validation set.
  • Models: They tested across three major ViT architectures: the vanilla ViT-B/16, the distilled DeiT-B, and the hierarchical Swin-B.

Key Insights and Ideas

  • Semantic Content > Attention: The core "aha moment" is that patch embeddings contain richer, more stable information for explanations than the volatile attention weights used by previous methods.
  • The Redundancy of ViTs: The paper shows that ViT feature maps are much more similar to one another than CNN feature maps (see Figure 4). This discovery allows for clustering, making mask-based explanation—usually a slow process—much faster.
  • ViTs are "Shape-Heady": Because ViTs have a strong global context, they can recognize an object just by its masked-out silhouette. If you don't add noise to your masks, your "explanation" might just be measuring the model's ability to recognize a hole in the image (Figure 5).
  • Causal Overdetermination: ViTs are remarkably robust. In about 21% of ImageNet cases, the model maintains a confidence score > 0.9 even when significant portions of the image are masked. Without PCB correction, this robustness "smears" the saliency map, making it look like the coverage frequency map rather than a targeted explanation.
Figure 4: ViT masks has lower variance then CNN masks. (a) Dis- tribution of pairwise similarities (Sim(i, j)) between masks for the goldfish image; (b) Distribution of mean pairwise mask similar- itiy (mSim) for all images in the ImageNet validation set.

Key Results

ViT-CX outperformed all baselines (including CGW, TAM, and Score-CAM) across several metrics:

  • Faithfulness: It achieved the lowest Deletion AUC (meaning it identifies the most critical pixels first) and the highest Insertion AUC. In some tests, its Deletion AUC was 10% lower than the next best method.
  • Interpretability: In the Pointing Game (which checks if the highest saliency point falls within the object's bounding box), ViT-CX reached accuracies of 86-92%, significantly higher than attention-based methods.
  • Efficiency: By using clustering, ViT-CX explains an image in ~1.15 seconds, compared to over 77 seconds for methods using thousands of random masks.

Limitations and Future Work

  • Speed: While much faster than previous mask-based methods, it is still slower than simple gradient-based methods (like Grad-CAM), which can run in milliseconds.
  • Scope: The current work focuses on image classification. The authors suggest that future work should extend these causal concepts to more complex tasks like object detection and semantic segmentation.
  • Hyperparameters: The method relies on a distance threshold for clustering and a noise level for debiasing, which might require tuning for different model architectures.

Summary updated

Abstract

Despite the popularity of Vision Transformers (ViTs) and eXplainable AI (XAI), only a few explanation methods have been designed specially for ViTs thus far. They mostly use attention weights of the [CLS] token on patch embeddings and often produce unsatisfactory saliency maps. This paper proposes a novel method for explaining ViTs called ViT-CX. It is based on patch embeddings, rather than attentions paid to them, and their causal impacts on the model output. Other characteristics of ViTs such as causal overdetermination are also considered in the design of ViT-CX. The empirical results show that ViT-CX produces more meaningful saliency maps and does a better job revealing all important evidence for the predictions than previous methods. The explanation generated by ViT-CX also shows significantly better faithfulness to the model. The codes and appendix are available at https://github.com/vaynexie/CausalX-ViT.
BibTeX
@inproceedings{xie2023vit,
  author = {Weiyan Xie and Xiao-Hui Li and Caleb Chen Cao and Nevin L. Zhang},
  title = {{ViT-CX: Causal Explanation of Vision Transformers}},
  booktitle = {International Joint Conference on Artificial Intelligence},
  year = {2023},
  url = {https://openreview.net/forum?id=-7zwxgME3q_},
}
Figure