Statistical Test for Attention Map in Vision Transformer

Tomohiro Shiraishi, Daiki Miwa, Teruyuki Katsuoka, Vo Nguyen Le Duy, Kouichi Taji, Ichiro Takeuchi

Abstract

The Vision Transformer (ViT) demonstrates exceptional performance in various computer vision tasks. Attention is crucial for ViT to capture complex wide-ranging relationships among image patches, allowing the model to weigh the importance of image patches and aiding our understanding of the decision-making process. However, when utilizing the attention of ViT as evidence in high-stakes decision-making tasks such as medical diagnostics, a challenge arises due to the potential of attention mechanisms erroneously focusing on irrelevant regions. In this study, we propose a statistical test for ViT's attentions, enabling us to use the attentions as reliable quantitative evidence indicators for ViT's decision-making with a rigorously controlled error rate. Using the framework called selective inference, we quantify the statistical significance of attentions in the form of p-values, which enables the theoretically grounded quantification of the false positive detection probability of attentions. We demonstrate the validity and the effectiveness of the proposed method through numerical experiments and applications to brain image diagnoses.

Introduction: The Problem of "Hallucinated" Importance

When a Vision Transformer (ViT) classifies an image, researchers often turn to its attention map to interpret the decision. In high-stakes fields like medical diagnostics, if a ViT identifies a brain tumor, the attention map should ideally highlight the lesion. However, deep learning models are prone to "hallucinating" importance—focusing on irrelevant background noise that happens to correlate with the target class in training data.

This issue stems from selection bias. In traditional statistics, one cannot use the same data to both formulate a hypothesis (e.g., "this specific cluster of pixels is important") and test that hypothesis. Because the attention region is selected after looking at the image, a standard "naive" statistical test will almost always yield a significant $p$-value, even if the image contains only noise. This research treats an attention map as a data-driven hypothesis that requires rigorous validation to distinguish genuine features from random artifacts.

Methodology: Selective Inference for ViTs

To address the "double-dipping" problem, the authors employ Selective Inference (SI). The goal of SI is to perform a hypothesis test conditioned on the selection event. It asks: "Given that our model chose this specific region to attend to, how likely is it that the pixel intensity difference between the inside and outside of this region occurred by chance?"

Implementing SI for ViTs is challenging because their attention mechanisms are highly non-linear. Unlike previous methods designed for piecewise linear CNNs, this framework introduces:

  1. A New Test Statistic: Significance is defined by the difference in mean pixel intensity inside versus outside the attention region.
  2. Adaptive Grid Search: To calculate $p$-values, the researchers developed an algorithm that searches the data space using Lipschitz continuity to find the boundaries where the attention map would change.
  3. Forward-Mode Auto-Differentiation: This technique makes the grid search efficient by calculating derivatives of the attention map, allowing the algorithm to bypass non-informative regions of the data space.

Experimental Setup

The method was evaluated using two primary datasets:

  • Synthetic Datasets: 1,000 "null" images (Gaussian noise) and 1,000 "positive" images (noise with a signal patch) to measure False Positive rates precisely.
  • Real-World Brain Image Dataset: 1,880 images (939 with tumors, 941 without) from a study by Buda et al. (2019) to test clinical utility.

Key Results and Discussion

The proposed "adaptive" method successfully controlled the Type I error rate (false positives) at the target significance level (e.g., $\alpha = 0.05$) across various ViT architectures (Small to Huge). In contrast, "naive" statistical tests were shown to be essentially useless, reporting $p$-values of ~0.000 (indicating high significance) nearly 100% of the time, even on pure noise.

Comparison of attention map significance in brain tumor diagnosis. The pipeline shows how input images are processed through a Transformer Encoder and Predictor to generate attention maps and regions. In the positive case (top), the selective p-value confirms significance, while in negative cases, it helps avoid false positives.

In brain tumor experiments, the proposed method provided high $p$-values (e.g., 0.801) for healthy brains, correctly flagging the attention as non-significant noise. Meanwhile, it maintained near-zero $p$-values for actual tumors, demonstrating significantly higher statistical power than conservative methods like the Bonferroni correction.

Limitations and Future Work

While effective, the method relies on heuristics to estimate the Lipschitz constant, which may require tuning for specialized architectures. Additionally, while faster than fixed grid searches, selective inference adds computational overhead. Future work aims to extend this framework to other feature attribution methods beyond simple attention maps and to explore robustness against more structured, non-Gaussian noise.

Summary updated

BibTeX
@inproceedings{shiraishi2024statistical,
  author = {Tomohiro Shiraishi and Daiki Miwa and Teruyuki Katsuoka and Vo Nguyen Le Duy and Kouichi Taji and Ichiro Takeuchi},
  title = {{Statistical Test for Attention Map in Vision Transformer}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=uLonuOfrwp},
}
Figure