Counterfactual Generation and Fairness Evaluation Using Adversarially Learned Inference

Saloni Dash, Amit Sharma

Abstract

Counterfactual examples for an input—perturbations that change specific features but not others—have been shown to be useful for evaluating bias of machine learning models, e.g., against specific demographic groups. However, generating counterfactual examples for images is non-trivial due to the underlying causal structure on the various features of an image. To be meaningful, generated perturbations need to satisfy constraints implied by the causal model. We present a method for generating counterfactuals by incorporating a structural causal model (SCM) in an improved variant of Adversarially Learned Inference (ALI), that generates counterfactuals in accordance with the causal relationships between attributes of an image. Based on the generated counterfactuals, we show how to explain a pre-trained machine learning classifier, evaluate its bias, and mitigate the bias using a counterfactual regularizer. On the Morpho-MNIST dataset, our method generates counterfactuals comparable in quality to prior work on SCM-based counterfactuals (DeepSCM), while on the more complex CelebA dataset our method outperforms DeepSCM in generating high-quality valid counterfactuals. Moreover, generated counterfactuals are indistinguishable from reconstructed images in a human evaluation experiment and we subsequently use them to evaluate the fairness of a standard classifier trained on CelebA data. We show that the classifier is biased w.r.t. skin and hair color, and how counterfactual regularization can remove those biases.

Introduction

Machine learning models frequently inherit and amplify biases present in their training data, often relying on "spurious correlations" rather than causal relationships. For instance, a classifier might associate "maleness" with "doctor-ness" if the training set is imbalanced. Traditional fairness metrics that rely on group associations are often insufficient because features are causally linked (e.g., age causes gray hair). To rigorously audit these models, we require counterfactuals: if we take a specific image and change only a sensitive attribute like skin color, does the model’s prediction change?

Generating such counterfactuals for high-dimensional image data is challenging. It requires modifying high-level concepts while preserving the identity and "essence" of the original image, all while respecting the underlying causal structure. This paper introduces ImageCFGen, a framework that leverages causal reasoning and generative AI to produce high-quality counterfactual images for bias evaluation and mitigation.

Methodology: ImageCFGen and CSALI

The ImageCFGen framework follows Judea Pearl’s three-step causal inference process:

  1. Abduction: An encoder infers the latent features ($z$) of a specific input image.
  2. Action: An intervention is performed on a specific attribute (e.g., changing Skin Color from dark to light) based on a pre-defined Structural Causal Model (SCM).
  3. Prediction: A generator creates a new counterfactual image ($x_c$) using the modified attributes ($a_c$) and the original latent features.
The ImageCFGen framework architecture, illustrating the flow from input features to counterfactual generation and classification.

To handle complex datasets like CelebA, we developed Cyclic Style ALI (CSALI). This approach improves upon standard Adversarially Learned Inference (ALI) by incorporating a style-based generator architecture (similar to StyleGAN) for enhanced realism. Furthermore, a Cyclic Cost Minimization step is introduced to ensure that the reconstructed image ($x_r$) is a faithful reproduction of the original input. This high-fidelity reconstruction is critical; if the identity of the subject is lost during reconstruction, any change in the classifier's prediction cannot be confidently attributed to the modified attribute.

Finally, we propose a Counterfactual Regularizer. This loss function penalizes a classifier if its predictions for an original image and its counterfactual version differ, effectively teaching the model to ignore sensitive attributes that should not influence the outcome.

Experimental Results

Quality and Realism

On the complex CelebA dataset, ImageCFGen achieved an FID score of 21.269, significantly outperforming the previous state-of-the-art causal model, DeepSCM. In a human evaluation experiment, participants were only able to distinguish counterfactuals from reconstructions about 50% of the time, indicating that the generated images are indistinguishable from standard reconstructions.

Bias Discovery and Mitigation

Using ImageCFGen, we audited a standard classifier trained to predict "Attractiveness" on CelebA. We discovered significant bias toward Pale Skin. For certain hair colors, changing an image to Pale Skin increased the probability of an "Attractive" prediction by nearly 94%.

By applying our counterfactual regularizer, we successfully mitigated these biases. For example, the bias score for the combination of Black Hair + Pale Skin was reduced from 0.159 to 0.032 without a significant loss in overall model accuracy.

Conclusion

This work demonstrates that integrating causal structures into generative models is essential for meaningful fairness evaluation in computer vision. While ImageCFGen requires a pre-defined causal graph, it provides a rigorous path toward identifying and fixing hidden biases. Future research will focus on Causal Discovery to automatically learn these feature relationships directly from data, further automating the fairness auditing process.

Summary updated

Abstract

Counterfactual examples for an input -- perturbations that change specific features but not others -- have been shown to be useful for evaluating bias of machine learning models, e.g., against specific demographic groups. However, generating counterfactual examples for images is non-trivial due to the underlying causal structure on the various features of an image. To be meaningful, generated perturbations need to satisfy constraints implied by the causal model. We present a method for generating counterfactuals by incorporating a structural causal model (SCM) in an improved variant of Adversarially Learned Inference (ALI), that generates counterfactuals in accordance with the causal relationships between attributes of an image. Based on the generated counterfactuals, we show how to explain a pre-trained machine learning classifier, evaluate its bias, and mitigate the bias using a counterfactual regularizer. On the Morpho-MNIST dataset, our method generates counterfactuals comparable in quality to prior work on SCM-based counterfactuals (DeepSCM), while on the more complex CelebA dataset our method outperforms DeepSCM in generating high-quality valid counterfactuals. Moreover, generated counterfactuals are indistinguishable from reconstructed images in a human evaluation experiment and we subsequently use them to evaluate the fairness of a standard classifier trained on CelebA data. We show that the classifier is biased w.r.t. skin and hair color, and how counterfactual regularization can remove those biases.
BibTeX
@inproceedings{dash2022counterfactual,
  author = {Saloni Dash and Amit Sharma},
  title = {{Counterfactual Generation and Fairness Evaluation Using Adversarially Learned Inference}},
  booktitle = {IEEE/CVF Winter Conference on Applications of Computer Vision},
  year = {2022},
  doi = {10.1109/wacv51458.2022.00393},
}
Figure