Introduction
Shapley values are widely considered the "gold standard" for explaining machine learning model predictions, but they are notoriously slow to calculate. This paper introduces ViT Shapley, a novel method that trains a dedicated explainer model to predict these values for Vision Transformers (ViTs) in a single forward pass. This approach offers a massive speedup while outperforming traditional interpretability methods like GradCAM and attention maps.
The Challenge of Explaining Vision Transformers
Vision Transformers have taken the computer vision world by storm, but understanding why they make a specific prediction remains difficult. Most researchers look at "attention maps"—the internal weights the model assigns to different image patches. However, recent studies suggest these maps can be misleading; a high attention score doesn't always mean that a patch was critical for the final classification.
The theoretically ideal solution is Shapley values, a concept from game theory that assigns "credit" to each input feature (image patch) based on its marginal contribution to the outcome. The catch? Calculating exact Shapley values requires evaluating the model on every possible subset of input features. For a standard ViT with 196 patches, that entails $2^{196}$ combinations—an impossible computational task. Even approximation methods like KernelSHAP can require over 100,000 model evaluations per image to converge.
A "Learning-to-Explain" Framework
The authors propose shifting the computational burden from test-time calculation to a one-time training phase. Their approach consists of three main pillars:
- Attention Masking for Feature Removal: To calculate a feature's contribution, you must be able to "remove" it. Instead of zeroing out pixels (which creates unnatural artifacts the model hasn't seen), the authors leverage the ViT architecture itself. They mask the attention values of "missing" tokens, effectively telling the model to ignore those patches entirely during its internal calculations.
- The Surrogate Model: Since standard ViTs aren't used to seeing missing data, the authors fine-tune the classifier (or a surrogate) using random masking. This ensures the model provides sensible predictions even when only partial information is available.
- The Explainer Model (ViT Shapley): This is the core innovation. They train a separate ViT model to take an image and a target class as input and output a vector of Shapley values for all patches. Crucially, they don't need "ground truth" Shapley values for training. Instead, they use a specific loss function based on weighted least squares that is mathematically proven to minimize the estimation error.
Key Insights and Results
The researchers evaluated their method on three diverse image datasets: ImageNette, MURA (musculoskeletal X-rays), and Oxford-IIIT Pets.
- Learning vs. Sampling: The central insight is that explanation can be treated as a supervised learning problem where the "label" is implicitly defined by the game-theoretic properties of Shapley values.
- Attention is Not Explanation: The paper reinforces that raw attention weights are a poor proxy for feature importance. ViT Shapley often identifies critical features that attention maps miss.
- Massive Speedup: Once trained, ViT Shapley generates explanations in a single forward pass (taking ~10ms). To reach the same level of accuracy, the standard KernelSHAP method would require roughly 120,000 model evaluations per image.
- Superior Accuracy: On "Insertion" and "Deletion" metrics—which measure how fast a model's confidence rises or drops as you add or remove important patches—ViT Shapley consistently outperformed GradCAM, LRP, and Attention Rollout.
Limitations and Future Work
While the explainer is lightning-fast at test time, the initial training is expensive. Training the explainer model took approximately 19 hours for ImageNette and 60 hours for the MURA dataset on high-end GPUs.
The authors note that while the method works exceptionally well for image patches, future work could extend this framework to NLP models (applying similar logic to text tokens), arbitrary feature grouping (explaining features at the level of semantic objects rather than fixed square patches), and improving the training efficiency of the explainer model itself.
Summary updated