Explainable AI: Context-Aware Layer-Wise Integrated Gradients for Explaining Transformer Models
Organizations: College of Engineering and Applied Science, University of Colorado Colorado Springs, Colorado Springs, 80918, CO, USA
Abstract
Transformer models achieve state-of-the-art performance across domains and tasks, yet their deeply layered representations make their predictions difficult to interpret. Existing explainability methods rely on final-layer attributions, capture either local token-level attributions or global attention patterns without unification, and lack context-awareness of inter-token dependencies and structural components. They also fail to capture how relevance evolves across layers and how structural components shape decision-making. To address these limitations, we proposed the Context-Aware Layer-wise Integrated Gradients (CA-LIG) Framework, a unified hierarchical attribution framework that computes layer-wise Integrated Gradients within each Transformer block and fuses these token-level attributions with class-specific attention gradients. This integration yields signed, context-sensitive attribution maps that capture supportive and opposing evidence while tracing the hierarchical flow of relevance through the Transformer layers. We evaluate the CA-LIG Framework across diverse tasks, domains, and transformer model families, including sentiment analysis and long and multi-class document classification with BERT, hate speech detection in a low-resource language setting with XLM-R and AfroLM, and image classification with Masked Autoencoder vision Transformer model. Across all tasks and architectures, CA-LIG provides more faithful attributions, shows stronger sensitivity to contextual dependencies, and produces clearer, more semantically coherent visualizations than established explainability methods. These results indicate that CA-LIG provides a more comprehensive, context-aware, and reliable explanation of Transformer decision-making, advancing both the practical interpretability and conceptual understanding of deep neural models.
Figures & tables
| Perturbation | Class | GradCAM [ 61 ] | LRP- [ 9 ] | LRP (Attn+Grad) [ 10 ] | IG [ 70 ] | Ours | |
|---|---|---|---|---|---|---|---|
| Insertion | Predicted | 0.424 | 0.448 | 0.567 | 0.473 | 0.617 | |
| Deletion | Predicted | 0.374 | 0.437 | 0.237 | 0.346 | 0.215 | |
Appendix figures & tables8 assets
Supplementary material from the paper’s appendix.
Appendix
| Aspect | IG [ 70 ] | Integrated Hessians [ 31 ] | Transformer-LRP [ 10 ] | CA-LIG Framework (Ours) |
|---|---|---|---|---|
| Core Principle | Path-integrated gradients from baseline to input | Second-order IG using Hessians for interaction effects | LRP/Deep Taylor rules | Layer-wise IG fused with class-specific attention gradients |
| Primary Objective | Token-level importance at input layer. | Quantify pairwise feature interactions. | Propagate and conserve relevance across attention and residuals. | Produce hierarchical, context-aware token relevance across layers. |
| Derivative Order | First-order | Second-order | Rule-based | First-order IG with gradient-weighted attention integration |
| Granularity | Input-level token salience | Interaction matrix between feature pairs | Single global input-level relevance map | Per-layer token attribution + fused contextual map + multi-layer rollout |
| Use of Attention | None | None | Implicit via LRP propagation rules | Explicit class-specific attention gradients . |
| Layer-wise Tracking | None (only final output layer) | None (interaction-focused) | Relevance flows through layers | Explicit LIG at each layer to model relevance trajectories. |
Transformer Interpretability
Transformer interpretability studies how attention, feed-forward layers, and hidden representations support model predictions and behavior.
See all 330 papers