To understand why a deep learning model makes a specific prediction, researchers often look at "saliency maps"—heatmaps that highlight which parts of an input image were most influential. However, traditional saliency methods often suffer from two conflicting problems: they are either spatially precise but "class-agnostic" (highlighting any object, regardless of the target class) or "class-specific" but spatially blurry.
A growing body of research addresses this by integrating gradient information directly into attention and attribution mechanisms. By using gradients as a filter, these methods ensure that explanations are both high-resolution and strictly relevant to a specific output category.
The Noise in Raw Attention
In Transformer-based models, the self-attention mechanism seems like a natural candidate for explainability. If a model attends to a specific patch, it must be important, right? Unfortunately, as Hila Chefer, Shir Gur, and Lior Wolf demonstrate in Generic Attention-model Explainability for Interpreting Bi-Modal and Encoder-Decoder Transformers, raw attention maps are often saturated with background noise.
The model might attend to a patch because it is a strong visual feature, even if that feature doesn't contribute to the final classification. To solve this, Chefer et al. propose weighting these attention scores by the gradients of the target class. This acts as a gate: only the attention that actually pushes the model toward the correct prediction is allowed to pass through to the final heatmap.
Gradients as a Class Specific Filter
The intuition behind using gradients for explainability is rooted in optimization. If we want to know why a model chose "Dog" instead of "Cat," we can look at the gradient of the "Dog" score with respect to the internal features.
Sylvestre-Alvise Rebuffi and colleagues explore this in There and Back Again: Revisiting Backpropagation Saliency Methods. They introduce NormGrad, which uses the norm of weight gradients to create saliency maps. By looking at how weights would change during an optimization step toward a target class, they capture features that are uniquely sensitive to that class.
This concept is taken further by Ameen Ali Ali and Lior Wolf in Visualization of Supervised and Self-Supervised Neural Networks via Attribution Guided Factorization. Their method, Attribution Guided Factorization (AGF), solves the "saliency bias"—the tendency of models to focus only on the most prominent object in an image. By combining gradient-based class specificity with pixel-level attribution, they can generate high-resolution maps that distinguish between multiple objects in the same scene.
Recursive Aggregation Across Layers
A single layer of a neural network only tells part of the story. Lower layers capture textures and edges, while higher layers capture semantic concepts. To get a complete picture, these methods often aggregate information across the entire depth of the network.
In the context of Vision Transformers (ViTs), Saurav Gupta and his team introduced Gradient-weighted Attention Rollout (GAR) in their work ViTOL: Vision Transformer for Weakly Supervised Object Localization. GAR recursively aggregates attention matrices from multiple layers, but crucially, it weights each layer's contribution by its gradient relative to the target class.
This recursive weighting ensures that as the "explanation" flows from the output back to the input patches, it is constantly refined to exclude features that are irrelevant to the specific category being localized. This allows ViTs to perform highly accurate object localization using only image-level labels, avoiding the "discriminative region" trap where a model only looks at the most obvious part of an object (like a bird's beak) rather than the whole animal.
Why It Works: The Synergy of Where and What
The success of these methods lies in the synergy between two different signals:
- Attribution/Attention (The "Where"): Identifies which spatial regions the model is processing.
- Gradients (The "What"): Identifies which of those regions actually drive the score for a specific class.
By multiplying these signals, researchers like Chefer and Gupta effectively perform a logical "AND" operation. The resulting heatmap only highlights regions that are both spatially attended to and class-relevant. This unified approach has moved the field away from simple, noisy backpropagation toward precise, interpretable visualizations that reflect the true decision-making process of complex models.