LibraGrad: Balancing Gradient Flow for Universally Better Vision Transformer Attributions

Faridoun Mehri, Mahdieh Soleymani Baghshah, Mohammad Taher Pilehvar
11/24/2024
cs.CVcs.AIcs.LG

Official code: NightMachinery/LibraGrad (12 stars, last commit 2024-11-27).

Abstract

Why do gradient-based explanations struggle with Transformers, and how can we improve them? We identify gradient flow imbalances in Transformers that violate FullGrad-completeness, a critical property for attribution faithfulness that CNNs naturally possess. To address this issue, we introduce LibraGrad -- a theoretically grounded post-hoc approach that corrects gradient imbalances through pruning and scaling of backward paths, without changing the forward pass or adding computational overhead. We evaluate LibraGrad using three metric families: Faithfulness, which quantifies prediction changes under perturbations of the most and least relevant features; Completeness Error, which measures attribution conservation relative to model outputs; and Segmentation AP, which assesses alignment with human perception. Extensive experiments across 8 architectures, 4 model sizes, and 4 datasets show that LibraGrad universally enhances gradient-based methods, outperforming existing white-box methods -- including Transformer-specific approaches -- across all metrics. We demonstrate superior qualitative results through two complementary evaluations: precise text-prompted region highlighting on CLIP models and accurate class discrimination between co-occurring animals on ImageNet-finetuned models -- two settings on which existing methods often struggle. LibraGrad is effective even on the attention-free MLP-Mixer architecture, indicating potential for extension to other modern architectures. Our code is freely available at https://github.com/NightMachinery/LibraGrad.

View on arXivView PDF

Code Implementations(1)

Balancing Gradient Flow for Universally Better Vision Transformer Attributions

120Jupyter NotebookNov 21, 20241 years ago

Similar Papers

Cite this paper

@article{mehri2024libragrad,
  title  = {LibraGrad: Balancing Gradient Flow for Universally Better Vision Transformer Attributions},
  author = {Faridoun Mehri and Mahdieh Soleymani Baghshah and Mohammad Taher Pilehvar},
  year   = {2024},
  eprint = {2411.16760},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2411.16760v1},
  journal = {CVPR 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2411.16760.svg)](https://codeofpaper.com/paper/2411.16760)

Discussion