Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers

Hila Chefer, Shir Gur, Lior WolfICCV 2021

Abstract: Transformers are increasingly dominating multi-modal reasoning tasks, such as visual question answering, achieving state-of-the-art results thanks to their ability to contextualize information using the self-attention and co-attention mechanisms. These attention modules also play a role in other computer vision tasks including object detection and image segmentation. Unlike Transformers that only use self-attention, Transformers with co-attention require to consider multiple attention maps in parallel in order to highlight the information that is relevant to the prediction in the model's input. In this work, we propose the first method to explain prediction by any Transformer-based architecture, including bi-modal Transformers and Transformers with co-attentions. We provide generic solutions and apply these to the three most commonly used of these architectures: (i) pure self-attention, (ii) self-attention combined with co-attention, and (iii) encoder-decoder attention. We show that our method is superior to all existing methods which are adapted from single modality explainability.

Introduction

While Transformers have revolutionized AI, they remain "black boxes." Understanding why a model like LXMERT or VisualBERT chose a specific answer in a Visual Question Answering (VQA) task is difficult. Existing explainability tools, such as Grad-CAM or Attention Rollout, were largely designed for simpler, single-modality models. They struggle with the complex "co-attention" mechanisms found in modern multi-modal Transformers, where the model must simultaneously weigh information from both an image and a text prompt. Without a way to track how information flows and mixes between these modalities, explanations often end up being noisy or misleading.

Methodology

The authors propose a method to maintain and update relevancy maps throughout the model's forward pass. Their approach hinges on three key technical pillars:

  1. Gradient-Weighted Attention: Instead of just looking at raw attention scores, they weight the attention maps using gradients. This ensures that the visualization reflects what actually influenced the final output class.
  2. Specific Update Rules: They define distinct mathematical rules for different types of interactions, specifically self-attention (how tokens within one modality relate) and co-attention (how tokens from one modality relate to another).
  3. Normalization: A critical component is the use of a row-wise normalization step. Because Transformers use residual connections, the "identity" of a token can overwhelm the new context gathered via attention. This normalization scheme balances the token's self-influence with its contextual relevance.
Figure 1: Comparison of Self-Attention (a) and Co-Attention (b) mechanisms, illustrating how inputs are routed through Multi-Head Attention layers.

Experimental Results

The researchers evaluated their method across several diverse tasks and architectures, including VQA (VisualBERT, LXMERT), Object Detection (DETR), and Image Classification (ViT).

Quantitative Validation

The method was validated using perturbation tests. In these tests, the "most relevant" pixels or tokens (according to the explainability method) are removed to see how quickly the model's accuracy drops. In tests on LXMERT and VisualBERT, the authors' method caused a much steeper decline in accuracy than baselines like Grad-CAM, proving it is better at identifying truly influential features.

Qualitative Visualizations

Qualitatively, the heatmaps produced are significantly more focused. While baseline methods often highlight the entire background or unrelated objects, this method tightly masks the specific object relevant to the input question. For example, on the MSCOCO dataset, the method achieved a 13.1 AP (Average Precision) for weakly supervised segmentation, outperforming the next best Transformer attribution method (7.2 AP) by a massive margin.

Extracted figure from page 6 of Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers

Conclusion and Future Work

This framework treats co-attention as a first-class citizen, allowing for clearer interpretation of multi-modal reasoning. The results show that when a model makes a mistake, this explainability method can show exactly where it looked, serving as a powerful debugging tool. Future work could involve extending this framework to more modalities like audio or video, or using these high-quality relevancy maps to improve model training through "explanation-supervised" learning.

Summary updated

BibTeX
@misc{chefer2021generic,
  author = {Hila Chefer and Shir Gur and Lior Wolf},
  title = {{Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers}},
  year = {2021},
  eprint = {2103.15679},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.15679},
}
Figure