Inspecting Explainability of Transformer Models with Additional Statistical Information

Hoang C. Nguyen, Haeil Lee, Junmo KimarXiv 2023 · DOI

Introduction

As Vision Transformers (ViTs) become increasingly dominant in computer vision, the need for robust Explainable AI (XAI) tools has grown. Understanding why a model classifies an image—for instance, identifying a cat based on its ears rather than background noise—is crucial for debugging and trust. However, existing state-of-the-art methods like "Transformer Attribution" encounter significant hurdles when applied to hierarchical architectures such as the Swin Transformer. In these models, heatmaps often erroneously highlight the corners of an image rather than the target object. This research identifies that the omission of internal Layer Normalization (LayerNorm) statistics in standard XAI frameworks is the primary cause of this failure.

Methodology

The authors propose a refined attribution framework that incorporates statistical scaling factors to improve localization accuracy. The method addresses two main challenges:

  1. Hierarchical Scale Integration: Swin Transformers reduce the number of tokens through patch merging as data moves deeper into the network. To maintain relevance tracking across these varying resolutions, the authors implement an averaging function that maps token influence from one resolution to the next.
  2. LayerNorm-Aware Attention: This is the core contribution. In Transformer blocks, LayerNorm scales tokens by their standard deviation. Standard XAI methods ignore this, leading to "unstable" tokens (often in image corners) dominating the attribution map. The authors modify the attention update rule to divide the attention matrix by the standard deviation of the tokens before normalization, ensuring the maps reflect the model's internal scaling.

Experimental Setup

The proposed method was evaluated on two key benchmarks using the ImageNet dataset:

  • Perturbation Tests: Measuring the drop in model confidence when "important" pixels (as identified by the XAI method) are removed.
  • Segmentation Accuracy: Assessing how well heatmaps align with human-defined object boundaries using Mean Intersection over Union (mIoU).

Analysis and Results

The integration of LayerNorm statistics effectively solves the "corner mystery." Patches in image corners often exhibit high variance; by accounting for LayerNorm's scaling, the proposed method prevents these patches from appearing artificially significant.

Qualitative comparison of attribution maps for Swin Transformer and ViT.

As shown in the visual comparisons, the baseline "Transformer Attribution" fails to localize objects in Swin Transformers, whereas the new "Attn Layer Norm" method produces distinct, accurate heatmaps for different classes (e.g., dog vs. cat).

Quantitative Performance

The quantitative results further validate the approach. On the Swin Transformer segmentation task, the proposed method achieved a mIoU of 49.38, a substantial improvement over the 39.06 baseline. Performance increased further to 54.19 when incorporating information from earlier layers.

Quantitative evaluation of segmentation and perturbation metrics.

Even for standard ViTs, where previous methods were already functional, the proposed method reached a mIoU of 62.95, outperforming the original Transformer Attribution (61.98) while utilizing a more streamlined calculation.

Conclusion and Future Work

This research demonstrates that auxiliary layers like LayerNorm are not merely "housekeeping" components but contain vital information for feature importance. By incorporating these statistics, the authors have bridged the explainability gap for hierarchical Transformers. Future research may explore more complex multi-layer integration strategies and investigate whether these statistical insights can similarly enhance the explainability of Large Language Models (LLMs) in natural language processing.

Summary updated

BibTeX
@misc{nguyen2023inspecting,
  author = {Hoang C. Nguyen and Haeil Lee and Junmo Kim},
  title = {{Inspecting Explainability of Transformer Models with Additional Statistical Information}},
  year = {2023},
  eprint = {2311.11378},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2311.11378},
}
Figure