AttCAT: Explaining Transformers via Attentive Class Activation Tokens

Yao Qiang, Deng Pan, Chengyin Li, Xin Li, Rhongho Jang, Dongxiao ZhuNeurIPS 2022

Transformers have revolutionized AI, yet their inner workings remain notoriously opaque. This NeurIPS 2022 paper introduces AttCAT (Attentive Class Activation Tokens), a novel method for explaining the decisions of Transformer models. By combining feature magnitudes, gradients, and attention weights, AttCAT provides a significantly more "faithful" look into the black box of NLP and Computer Vision models.

The Problem with Current Explanations

Despite their dominance, Transformers are difficult to interpret. Researchers typically rely on attention weights to visualize what the model "looks at." However, the authors identify three major flaws with this standard approach:

  1. Attention $\neq$ Importance: High attention weights do not guarantee a feature is important if the underlying feature magnitude is negligible. It is akin to looking at a map without knowing the traffic volume; you see the path, but not the intensity.
  2. The Skip-Connection Gap: A massive portion of information in a Transformer flows through "skip connections" (identity mappings). Standard explanation methods often ignore this entirely, missing critical information flows.
  3. Lack of Interaction: Standard gradient-based methods treat tokens independently, failing to capture how they interact to create contextual meaning.
Illustration of self-attention and skip connections, highlighting the importance of feature magnitudes alongside attention weights.

Because of these flaws, current techniques often lack "faithfulness"—meaning the words they highlight as important aren't actually the ones driving the model's prediction.

The AttCAT Solution

To address these gaps, the authors propose a two-step approach inspired by the popular Grad-CAM technique used in Computer Vision:

  • Class Activation Tokens (CAT): First, the "impact" of a token is defined by taking the Hadamard product (element-wise multiplication) of its feature vector ($h$) and its gradient ($\nabla h$). This captures both the magnitude of the feature and its specific contribution to the final class prediction. Because CAT is derived from the layer outputs, it implicitly captures the information flowing through skip connections.
  • Attentive CAT (AttCAT): Next, these CAT scores are weighted by the self-attention weights ($\alpha$). This ensures the explanation accounts for how tokens interact with one another across the sequence.
  • Summation over Rollout: Most existing methods use "Rollout" (multiplying scores across layers), which tends to wash out signals in deeper layers where attention becomes uniform. AttCAT instead sums the impact scores across all layers, preserving the distinct signals found in shallower parts of the network.

Crucially, AttCAT captures directionality: it can determine if a word had a positive impact (supporting the prediction) or a negative impact (contradicting it).

Key Results and Faithfulness

AttCAT was evaluated across a wide variety of benchmarks (SST2, IMDB, MNLI, SQuAD) and architectures (BERT, DistilBERT, RoBERTa). It consistently outperformed baselines like Raw Attention, Rollout, Grad-SAM, and TransAtt.

  • Faithfulness (AOPC & LOdds): The true test of an explanation is what happens when you remove the "important" features. When the top tokens identified by AttCAT were deleted, the model's prediction probability dropped much more sharply than with other methods. This proves AttCAT is identifying the actual drivers of the prediction.
  • Precision@K: On Question Answering tasks (SQuAD), AttCAT was significantly better at highlighting the actual ground-truth answer tokens within its top-ranked results.
  • Confidence: Using the Kendall-$\tau$ correlation, the authors showed that AttCAT is highly "confident"—it assigns very different importance scores to tokens depending on which class is being predicted, whereas baselines often produce similar maps regardless of the target class.
AOPC and LOdds evaluation metrics demonstrating AttCAT's superior faithfulness compared to baseline explanation methods.

Qualitatively, visualizations show that while baselines often highlight irrelevant punctuation or stop words, AttCAT successfully zooms in on high-impact words (e.g., "boring," "didn't") that dictate sentiment or meaning.

Limitations and Future Work

While the method is theoretically general, the experiments in this paper focused primarily on BERT-based architectures for NLP. The authors note that while AttCAT can be naturally extended to Vision Transformers (ViT), providing extensive benchmarks for CV-specific tasks like image classification or object detection remains a primary direction for future work.

Summary updated

BibTeX
@inproceedings{qiang2022attcat,
  author = {Yao Qiang and Deng Pan and Chengyin Li and Xin Li and Rhongho Jang and Dongxiao Zhu},
  title = {{AttCAT: Explaining Transformers via Attentive Class Activation Tokens}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=9uxuTWYuV0},
}
Figure