Machine Learning from Explanations

Jiashu Tao, Reza Shokri

TL;DR

When trained on small or imbalanced datasets, machine learning models often rely on arbitrary, spurious shortcuts rather than true underlying logic. This paper introduces a novel two-stage training pipeline that uses simple explanation masks (highlighting key features) to guide a model's latent representations. By alternating between optimizing for label accuracy and aligning latent features with human explanations, the method achieves up to a 10x reduction in sample complexity while remaining highly robust to spurious correlations.

What Problem Does This Paper Address?

Standard empirical risk minimization (ERM) works exceptionally well when data is abundant, but it struggles in small-data regimes, under severe class imbalances, or when data contains natural spurious correlations. Because standard labels only specify what an object is, but not why, models have too much freedom in choosing their decision functions. They often latch onto irrelevant background features or majority-class biases that happen to align with the training labels but fail to generalize to unseen data.

Prior attempts to solve this typically add an "explanation misalignment loss" directly to the standard label loss. However, the authors point out that this joint optimization creates a "race condition" where the gradients of the two loss terms counteract each other, leading to slow convergence or trapping the model in poor local optima.

Methods

To eliminate gradient conflict, the authors propose a two-stage optimization pipeline that separates label learning from explanation alignment, utilizing a dedicated mapping layer ($m$) inserted between the convolutional feature extractor ($f$) and the fully connected classifier ($c$).

A demonstration of how the proposed training pipeline uses the explanation.

The training alternates between two distinct stages within each cycle:

  1. Stage 1 (Label Optimization): A standard forward pass is performed on the full image. The cross-entropy loss ($L_{CE}$) is computed against the ground-truth label, and gradients are backpropagated to update the entire model ($f$, $m$, and $c$).
  2. Stage 2 (Attention Tuning): The input image is multiplied by a binary explanation mask ($e(x)$) to isolate the "true reason" region (creating a masked image $x'$). The feature maps of both the original image (passed through $f$ and $m$) and the masked image (passed only through $f$) are normalized using a softmax function. The pipeline then minimizes the KL divergence between these two feature distributions ($L_{feat}$). Crucially, the gradients from this stage are backpropagated to update only the mapping layer ($m$), preventing the feature extractor from receiving conflicting updates.

Datasets

The approach was evaluated on three binary classification tasks:

  • Triangle Orientation Dataset: A synthetic grayscale dataset where triangles pointing upwards belong to Class 1. The explanation mask highlights the spatial arrangement of the vertex and the bottom line.
  • Fox vs Cat Dataset: A synthetic dataset where foxes have triangular heads and cats have round heads. The explanation mask isolates the vertex of the triangle or the arc of the circle.
  • Bird Dataset: A challenging, real-world fine-grained subset of the CUB-200-2011 dataset focusing on two visually identical species (Indigo Buntings vs. Blue Grosbeaks) that differ primarily by beak size. The explanation mask highlights the beak.
Examples of the Fox vs Cat dataset and their corresponding explanation masks.

To rigorously verify if the models actually learned the intended rules, the authors also evaluated them on alternative test sets sharing the same underlying logic (e.g., a Pentagon Orientation Dataset derived from the triangle rules).

Key Insights and Ideas

  • Sequential over Joint Optimization: Alternating the optimization steps completely bypasses the gradient interference that plagues joint-loss methods like Gradient Regularization (Grad Reg).
  • The Mapping Layer as a Filter: By freezing the feature extractor during the explanation stage and only updating the mapping layer, the network effectively learns to filter out irrelevant background noise and amplify the signals coming from the human-highlighted regions.
  • Drastically Higher Model Consistency: Models trained with explanations demonstrate exceptionally high pairwise prediction agreement (often >92%). Without explanations, different training runs yield models with similar training accuracies but wildly different, unpredictable decision boundaries.

Key Results

  • Massive Sample Efficiency: The proposed method achieves a 3x to 10x reduction in the dataset size required to reach target performance thresholds compared to standard training. For instance, on the Triangle dataset, our method with just 10 samples outperforms vanilla training with 100 samples.
  • Robustness to Severe Imbalance: In a highly imbalanced setting (9:1 class ratio), the method maintains high test accuracy on balanced test sets, even when explanations are only provided for the minority class ("Sparse" setting).
  • Immunity to Spurious Features: When trained on datasets intentionally corrupted with highly correlated spurious artifacts (like colored squares in the corners), models trained with this method ignore the shortcuts and successfully learn the true geometric or biological features.
Test accuracy on clean test sets when models are trained on a spurious training set.

Limitations and Future Work

While highly effective, the authors note a few limitations:

  1. Soft Constraints: Because this is a loss-based approach rather than constrained optimization, it cannot strictly guarantee that the model only uses the provided reasons to make decisions.
  2. Dataset Scarcity: Real-world datasets that include high-quality, dense feature-level explanations are currently rare and expensive to curate.

For future work, the authors plan to extend this framework to multi-class classification and adapt it to Large Language Models (LLMs). In the LLM domain, the explanation masks would correspond to critical tokens in a prompt, and the mapping layer would function similarly to a LoRA (Low-Rank Adaptation) block appended to attention layers.

Summary updated

BibTeX
@misc{tao2025machine,
  author = {Jiashu Tao and Reza Shokri},
  title = {{Machine Learning from Explanations}},
  year = {2025},
  eprint = {2507.04788},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2507.04788},
}
Figure