Counterfactual Visual Explanations

Yash Goyal, Ziyan Wu, Jan Ernst, Dhruv Batra, Devi Parikh, Stefan Lee

Introduction: The Need for Contrastive Explanations

Most current "explainable AI" (XAI) methods rely on feature attribution. If a model identifies a bird as a Crested Auklet, a tool like Grad-CAM might highlight the beak or the eyes to show what the model was "looking at."

However, humans often explain things contrastively: "Why is this an $X$ and not a $Y$?" Feature attribution fails here because many features (like eyes or wings) are shared across similar classes. This paper introduces a technique to explain AI decisions by generating counterfactual explanations. Instead of just highlighting important pixels, the system identifies the minimal functional changes—such as swapping a specific beak shape—that would flip the model's prediction from class $c$ to a different class $c'$.

Counterfactual explanation swapping a beak between two bird species

By swapping specific regions between a "query" image and a "distractor" image, the system provides discriminative, visual "what-if" scenarios. As the researchers demonstrate, these explanations significantly improve a human's ability to learn complex tasks like fine-grained bird classification.

Methods: The Minimum-Edit Counterfactual Problem

To generate these explanations, the authors treat a Convolutional Neural Network (CNN) as two distinct parts: a spatial feature extractor and a decision network.

Splitting a CNN into a spatial feature extractor and a decision network

To explain why query image $I$ is classified as $c$ instead of $c'$, they select a "distractor" image $I'$ that the model already views as class $c'$. The core of the approach is the Minimum-Edit Counterfactual Problem: finding a small number of spatial regions in the query image to replace with regions from the distractor image such that the model's prediction changes.

They propose two ways to solve this:

  1. Greedy Sequential Exhaustive Search: The system checks every possible pair of spatial cells between the two images and picks the one that increases the probability of the target class $c'$ the most. It repeats this until the classification flips.
  2. Continuous Relaxation: To handle larger images where exhaustive search is too slow, they use gradient-based optimization. They "soften" the selection process using a softmax-based gating mechanism, allowing the system to learn which regions to swap via backpropagation.

Crucially, these edits happen in the feature space of the model, not the raw pixel space. This ensures the explanations are "faithful" to the model's internal logic rather than just creating visually pleasing but irrelevant images.

Datasets

The researchers evaluated their method on four distinct datasets:

  • SHAPES: A synthetic dataset of colored geometric objects used for quantitative sanity checks.
  • MNIST: Hand-written digits (e.g., what stroke changes a '3' into a '5'?).
  • Omniglot: A dataset of characters from 50 different writing systems.
  • CUB-2011 (Caltech-UCSD Birds): A challenging fine-grained dataset of 200 bird species, used for the primary "machine teaching" experiments.

Key Insights

  • Contrastive is Better: Traditional saliency maps often highlight the same regions for different classes. Counterfactuals force the explanation to be discriminative, highlighting only what differs between two categories.
  • Faithfulness by Design: Because the method directly manipulates the features the model uses to make decisions, the resulting explanation is a true reflection of the model's "reasoning," not a post-hoc approximation.
  • Machine Teaching: The most profound insight is that these AI-generated explanations can actually make humans smarter. By showing a human "If this beak looked like that one, it would be a Cormorant," the AI acts as a specialized tutor for fine-grained details that a non-expert would otherwise miss.

Key Results

  • Human Learning: In a "machine teaching" study, humans trained with counterfactual explanations achieved 78.77% accuracy in bird classification, compared to 71.09% for those with no explanations and 74.29% for those using standard Grad-CAM.
  • Efficiency: The continuous relaxation method was highly effective, finding the same optimal regions as the exhaustive search nearly 80% of the time while being significantly faster.
  • Semantic Alignment: On the CUB dataset, the system's "edits" naturally gravitated toward semantically meaningful parts like beaks, crowns, and wings 75-80% of the time, even though the model was never explicitly told where those parts were.

Limitations and Future Work

  • Distractor Selection: The quality of the explanation depends heavily on the choice of the distractor image. Currently, the authors use random or "nearest neighbor" images; a more principled way to pick the "most informative" distractor remains an open question.
  • Visual Artifacts: Because the method swaps features and then visualizes them by superimposing pixel regions, the "composite" images can look disjointed or "Frankenstein-ish" if the birds are in different poses.
  • Model Dependency: The explanation is only as good as the underlying model. If the CNN is relying on background "spurious correlations" (like water for sea birds), the counterfactual will highlight the background rather than the bird.

Summary updated

BibTeX
@inproceedings{goyal2019counterfactual,
  author = {Yash Goyal and Ziyan Wu and Jan Ernst and Dhruv Batra and Devi Parikh and Stefan Lee},
  title = {{Counterfactual Visual Explanations}},
  booktitle = {International Conference on Machine Learning},
  year = {2019},
  url = {https://openreview.net/forum?id=ByWxV2-uWB},
}
Figure