Beyond Intuition: Rethinking Token Attributions inside Transformers

Jiamin Chen, Xuhong Li, Lei Yu, Dejing Dou, Haoyi Xiong

Abstract

Explaining the decision-making process of Transformer models is critical for trust and debugging. However, standard "intuitive" attribution methods often fail because they ignore the complex linear projections within attention blocks. This paper introduces a mathematically rigorous framework that decomposes attribution into "Attention Perception" and "Reasoning Feedback." By explicitly accounting for internal linear transformations, this method achieves up to 100x better approximation accuracy than traditional heuristics like Attention Rollout and provides significantly clearer, class-specific explanations across various architectures and model depths.

Introduction

To effectively debug and deploy Transformer models, researchers must understand which input tokens—whether words in a sentence or patches in an image—drive a model's prediction. Existing methods, such as Attention Rollout or Generic Attribution, typically rely on the intuitive assumption that tokens are simply linearly combined across layers. Crucially, these methods often ignore the internal linear transformation matrices ($W$) within attention blocks.

As models grow deeper (e.g., ViT-Large) or utilize diverse training strategies like Masked Autoencoders (MAE), these heuristic shortcuts lead to an accumulation of error. The resulting "noisy" explanations often highlight irrelevant background features or lose semantic coherence. This work replaces these heuristics with a formal derivation based on the chain rule, ensuring that attributions are grounded in the model's actual mathematical operations.

The Proposed Framework: Perception and Reasoning

The authors propose a novel framework that splits the attribution process into two distinct, mathematically derived stages: Attention Perception and Reasoning Feedback.

Overview of the proposed attribution framework decomposing Transformer operations into Perception and Reasoning.

1. Attention Perception ($P^{(L)}$)

This stage describes how tokens interact and integrate across $L$ successive blocks. Unlike previous methods that treat attention weights as simple scalars, the authors derive a recurrence formula that explicitly incorporates the linear projections ($W$ matrices). They offer two variants:

  • Token-wise: Utilizes the norms of token vectors to account for the scaling effects of linear projections.
  • Head-wise: Employs a "head importance" metric to weight the contributions of different attention heads.

2. Reasoning Feedback ($F^c$)

This component describes how the final pooled vector is utilized to predict a specific class ($c$). To filter out noise from irrelevant features, the framework applies Integrated Gradients (IG) to the final attention map. This ensures the resulting explanation is highly specific to the predicted class rather than just highlighting generally salient regions.

The final attribution map is generated by the Hadamard product of these two components, resulting in a representation that is both mathematically grounded and class-aware.

Experimental Results and Faithfulness

The framework was validated across a wide range of architectures (BERT, ViT-Base/Large, ViT-MAE, ViT-DINO) and tasks including ImageNet classification and NLP sentiment analysis.

Quantitative Superiority

In ImageNet-Segmentation benchmarks, the "Token-wise" (Ours-T) method achieved a 66.32 mIoU, significantly outperforming Attention Rollout (55.42) and the previous state-of-the-art, Generic Attribution (58.34). Furthermore, "Perturbation Tests" confirmed that the tokens identified by this method are indeed the most critical to the model's decision, as removing them caused the steepest decline in accuracy.

Robustness to Model Depth

A key finding is that while traditional methods often "break" or become extremely noisy in deeper models, this framework remains stable. In 24-layer models like ViT-Large, it continues to produce fine-grained, semantic attributions where others fail. The authors note that their Token-wise approximation is 20x to 100x more accurate at reflecting the model's internal state than Rollout.

Visual Analysis

Qualitatively, the heatmaps produced by this method are significantly more localized and semantically relevant. While generic methods might highlight an entire scene, this framework precisely identifies defining features, such as the specific features of a "border collie."

Comparison of attribution maps between Generic Attribution and the proposed method across different ViT variants.

As shown in the comparison above, the proposed method maintains high fidelity even when applied to models trained with different objectives, such as Masked Autoencoders (ViT-MAE), where standard attribution often produces scattered results.

Conclusion

By rethinking token attribution through the lens of formal mathematical decomposition rather than intuition, this work provides a more faithful window into the "black box" of Transformers. The separation of perception (how tokens mix) from reasoning (how classes are decided) allows for cleaner, more actionable explanations. Future work will look to extend this framework to Decoder-only architectures and explore its utility in model pruning and refinement.

Summary updated

BibTeX
@article{chen2023beyond,
  author = {Jiamin Chen and Xuhong Li and Lei Yu and Dejing Dou and Haoyi Xiong},
  title = {{Beyond Intuition: Rethinking Token Attributions inside Transformers}},
  journal = {Trans. Mach. Learn. Res.},
  year = {2023},
  url = {https://openreview.net/forum?id=UEK9E8DAKr},
}
Figure