Counterfactual confounding adjustment for feature representations learned by deep models: with an application to image classification tasks

Elias Chaibub Neto

Introduction

Deep Neural Networks (DNNs) have achieved remarkable success in various domains, yet they remain susceptible to "shortcut learning." This phenomenon occurs when models rely on spurious correlations—such as background color or environmental context—rather than the invariant features of the target object. Consequently, these models often fail when deployed in environments where these correlations no longer hold, a challenge known as dataset shift caused by selection bias.

Methodology: Post-Hoc Causal Adjustment

The core contribution of this work is a simple, post-hoc method to "deconfound" feature representations without retraining the entire model. The approach leverages the observation that the final layers of a DNN, particularly those preceding a softmax output, are mathematically linear. By extracting these high-level features, we can apply causal tools that were originally designed for simpler linear models.

A typical DNN architecture for digit classification, highlighting the learned feature representation used for counterfactual adjustment.

The proposed algorithm follows four primary steps:

  1. Feature Extraction: Activations are extracted from the final hidden layer ($X$) of a pre-trained DNN.
  2. Linear Deconfounding: Linear regression is used to model the influence of the confounder ($C$) and the label ($Y$) on these features.
  3. Counterfactual Shift: The influence of the confounder is mathematically subtracted to create "counterfactual features" ($X^*$). This represents what the feature would look like in a neutral environment.
  4. Linear Classification: A simple classifier (e.g., logistic regression) is trained on these cleaned features.

Causal Framework

The theoretical foundation of this method rests on causal modeling. By representing the relationships between features, labels, and confounders as Directed Acyclic Graphs (DAGs), we can identify how selection bias ($S$) distorts the learned representations in both training and testing phases.

Causal diagrams illustrating the relationships between features (X), labels (Y), and confounders (C) under selection bias (S) in training and test environments.

As shown in the causal diagrams, the features $X$ are influenced by both the true label $Y$ and the confounder $C$. In the training set, selection bias $S$ creates a spurious correlation between $C$ and $Y$. The counterfactual adjustment aims to break this link, ensuring the classifier relies solely on the causal path from $Y$ to $X$. Crucially, this method deconfounds the features at inference time, providing stability even when the test environment differs from the training environment.

Experimental Results

The method was validated using a "Colored MNIST" dataset, where digit color served as a strong confounder in the training set (e.g., digits 0-4 were 99% green). While a standard DNN's accuracy dropped significantly (from 99% to 85%) when the color-digit correlation was reversed in the test set, the proposed counterfactual adjustment maintained a stable accuracy of approximately 97% across all levels of dataset shift.

Furthermore, the method outperformed traditional data-balancing techniques like SMOTE. Statistical tests using partial correlations confirmed that the adjusted features $X^*$ were independent of the confounder $C$ given the label $Y$, indicating successful removal of the biased shortcuts.

Discussion and Limitations

This post-hoc adjustment offers a lightweight and flexible wrapper for existing large-scale models. However, it requires that confounders be explicitly observed and labeled in the dataset. Future research should address scenarios with latent (hidden) confounders and explore the application of these linear causal tools to more complex, high-dimensional environmental biases in natural images.

Summary updated

Abstract

Causal modeling has been recognized as a potential solution to many challenging problems in machine learning (ML). Here, we describe how a recently proposed counterfactual approach developed to deconfound linear structural causal models can still be used to deconfound the feature representations learned by deep neural network (DNN) models. The key insight is that by training an accurate DNN using softmax activation at the classification layer, and then adopting the representation learned by the last layer prior to the output layer as our features, we have that, by construction, the learned features will fit well a (multi-class) logistic regression model, and will be linearly associated with the labels. As a consequence, deconfounding approaches based on simple linear models can be used to deconfound the feature representations learned by DNNs. We validate the proposed methodology using colored versions of the MNIST dataset. Our results illustrate how the approach can effectively combat confounding and improve model stability in the context of dataset shifts generated by selection biases.
BibTeX
@misc{neto2020counterfactual,
  author = {Elias Chaibub Neto},
  title = {{Counterfactual confounding adjustment for feature representations learned by deep models: with an application to image classification tasks}},
  year = {2020},
  eprint = {2004.09466},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2004.09466},
}
Figure