Learning to Explain: A Model-Agnostic Framework for Explaining Black Box Models

Oren Barkan, Yuval Asher, Amit Eshel, Yehonatan Elisha, Noam KoenigsteinarXiv 2023

TL;DR

Learning to Explain (LTX) is a novel, model-agnostic framework that provides post-hoc explanations for black-box vision models, including both CNNs and Vision Transformers (ViTs). By training a dedicated "explainer" model through a two-stage process of pretraining and per-instance finetuning, LTX generates highly focused explanation maps using a counterfactual masking objective. It significantly outperforms existing state-of-the-art explainability methods across multiple quantitative metrics and produces cleaner, more intuitive heatmaps.

What Problem Does This Paper Address?

As deep learning models become more embedded in critical applications, understanding why a model made a specific prediction is vital. In computer vision, post-hoc explainability methods typically generate heatmaps highlighting the most influential regions of an input image.

However, existing techniques suffer from two major drawbacks:

  1. Architecture Dependence: Many dominant methods are tightly coupled to specific architectures—such as Grad-CAM for CNNs or Transformer Attribution for ViTs—making it difficult to apply a single framework across diverse model types.
  2. Deep Internal Access: Many methods require deep access to internal parameters, layer activations, or complex attention-weight aggregations.

The authors introduce LTX to bridge this gap. LTX is a truly model-agnostic framework that treats the target model as a frozen black box, requiring only the ability to compute gradients with respect to the input image.

Methods

The core idea behind LTX is to train a separate parametric model, the explainer ($e_\phi$), to predict an explanation mask ($m$) for a given image ($x$).

Fig. 1. The LTX framework: The explainer model eϕ is trained to explain the predictions of the explained model fθ based on prediction loss on the masked input Lpred and the regularization term Lmask (in this work, Linv and Lsmooth from Eq. 2 do not participate in the optimization). While the explained model fθ takes an active part in the optimization of eϕ, its weights are kept frozen throughout the LTX optimization process. The red lines illustrate gradient propagation.

The framework operates via a distinct optimization pipeline:

  • Masking Mechanism: The explainer generates a soft mask $m \in [0, 1]^n$. This mask is used to create a perturbed image ($x^m$) by keeping high-scoring regions intact and blending low-scoring regions with a learned background value ($z$).
  • The LTX Objective: The loss function balances two primary goals:
  • Prediction Loss ($L_{pred}$): Ensures that the target model ($f_\theta$) outputs the same prediction on the masked image ($x^m$) as it did on the original image.
  • Mask Regularization ($L_{mask}$): Uses Binary Cross-Entropy to force the mask to be as sparse and narrow as possible.

To maximize performance, LTX uses a two-stage training process:

  1. Pretraining: The explainer is initially trained on a small dataset to learn general features and highlight broadly influential regions.
  2. Per-Instance Finetuning: At test time, the explainer's weights are fine-tuned for a few steps on the specific single image being analyzed. This allows the mask to adapt precisely to the unique geometry and context of that instance.

Datasets

The authors evaluated LTX using the standard ImageNet ILSVRC 2012 dataset:

  • Pretraining Dataset: A highly compact subset of the ImageNet training set consisting of just 2,000 images (exactly one training example and one validation example per class).
  • Evaluation Dataset: The full ImageNet validation set containing 50,000 images across 1,000 classes.

Key Insights and Ideas

  • Instance-Level Finetuning is a Game-Changer: While pretraining gives the explainer a solid foundation, the per-instance finetuning step acts as a powerful refinement mechanism. It allows the model to shed background noise and lock onto the exact boundaries of the object responsible for the classification.
  • Input Gradients Suffice for Agnosticism: By routing information back from the explained model to the explainer solely via gradients of the input image, LTX bypasses the need to understand the internal mechanics (like attention matrices or specific convolutional layers) of the target model.
  • Counterfactual Masking as an Objective: Instead of asking "what features are present," LTX effectively asks, "what is the smallest amount of visual information I can leave unmasked so that the model doesn't change its mind?" This naturally yields tighter, more meaningful attributions.

Key Results

LTX was evaluated against top baselines (including GAE, T-Attr, and Grad-CAM) using standard perturbation metrics: Negative Perturbation (NEG), Positive Perturbation (POS), Insertion (INS), and Deletion (DEL).

  • Vision Transformers (ViT-B): LTX achieved a massive performance leap. On predicted classes, LTX scored 64.83 on NEG (compared to GAE's 54.61) and 11.19 on POS (where lower is better, compared to GAE's 17.32).
  • Convolutional Networks (ResNet101): LTX similarly dominated, hitting a NEG score of 61.13 (vs. Grad-CAM's 55.78) and a POS score of 8.65 (vs. Grad-CAM's 13.50).

Qualitatively, the visual differences are striking. LTX consistently produces cleaner heatmaps that tightly bound the target object, avoiding the diffuse "blobs" common in gradient-based alternatives.

Fig. 2. Comparison of ViT-B explanation maps for single-class images.

Limitations and Future Work

The authors note a couple of areas for improvement:

  • Aggressive Upsampling for CNNs: For models like ResNet101, the explainer outputs a low-resolution $7 \times 7$ map which is scaled up to $224 \times 224$ via bilinear interpolation. This can lead to overly smooth boundaries. Integrating a learned decoder (like a U-Net architecture) could preserve sharper spatial details.
  • Cross-Domain Expansion: While this paper focuses entirely on computer vision, the underlying framework of an explainer model optimizing a counterfactual mask is fundamentally domain-agnostic. The authors plan to extend LTX to Natural Language Processing (NLP) and recommender systems in future work.

Summary updated

BibTeX
@misc{barkan2023learning,
  author = {Oren Barkan and Yuval Asher and Amit Eshel and Yehonatan Elisha and Noam Koenigstein},
  title = {{Learning to Explain: A Model-Agnostic Framework for Explaining Black Box Models}},
  year = {2023},
  eprint = {2310.16584},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.16584},
}
Figure