Learning Invariant Representations using Inverse Contrastive Loss

Aditya Kumar Akash, Vishnu Suresh Lokhande, Sathya N. Ravi, Vikas Singh

Abstract

Learning invariant representations is a critical first step in a number of machine learning tasks. A common approach corresponds to the so-called information bottleneck principle in which an application dependent function of mutual information is carefully chosen and optimized. Unfortunately, in practice, these functions are not suitable for optimization purposes since these losses are agnostic of the metric structure of the parameters of the model. We introduce a class of losses for learning representations that are invariant to some extraneous variable of interest by inverting the class of contrastive losses, i.e., inverse contrastive loss (ICL). We show that if the extraneous variable is binary, then optimizing ICL is equivalent to optimizing a regularized MMD divergence. More generally, we also show that if we are provided a metric on the sample space, our formulation of ICL can be decomposed into a sum of convex functions of the given distance metric. Our experimental results indicate that models obtained by optimizing ICL achieve significantly better invariance to the extraneous variable for a fixed desired level of accuracy. In a variety of experimental settings, we show applicability of ICL for learning invariant representations for both continuous and discrete extraneous variables.

The Problem: Latent Space Collapse

In many machine learning applications, it is desirable to learn representations that are invariant to specific "extraneous" variables. This is crucial for fairness (e.g., ignoring race in credit scoring) and domain adaptation (e.g., ensuring medical diagnostics work across different scanner brands).

Standard approaches typically use compression regularizers to minimize mutual information between the representation and the extraneous variable. However, these methods often suffer from a "collapse paradox." As regularization strength ($\lambda$) increases, representations of data points with the same extraneous value tend to clump together into tight clusters. Paradoxically, this clumping makes it easier for an adversary to identify the extraneous variable, defeating the purpose of the regularizer.

Observed vs. Desired behavior of representation learning under varying regularization strengths. Standard methods (Observed) lead to cluster collapse, whereas ICL (Desired) promotes mixing.

Methods: Inverse Contrastive Loss (ICL)

To address this, the authors propose Inverse Contrastive Loss (ICL). While standard Contrastive Learning (CL) pulls similar points together and pushes dissimilar ones apart, ICL inverts this logic relative to the extraneous variable:

  1. Formal Inversion (FI): Samples sharing the same extraneous value are treated as "negative" pairs (repelled), while samples with different values are treated as "positive" pairs (attracted).
  2. Weighted Neighborhood Kinks (AWNK): Specific mathematical functions, such as exponential loss, are employed to ensure a persistent "push" force even at close distances, preventing the latent space from collapsing into single points.

For binary variables, ICL is mathematically equivalent to a Regularized Maximum Mean Discrepancy (R-MMD). This provides a theoretical link to energy functionals in physics, where the system behaves like a network of springs: repulsion between similar-label points and attraction between different-label points creates a well-mixed, invariant representation.

Experimental Results

The efficacy of ICL was evaluated across diverse benchmarks, including MNIST (style invariance), fairness datasets (Adult and German), rotation invariance (MNIST-ROT), and medical imaging (ADNI). The primary metric for invariance is the Adversarial Invariance Measure (A), where a lower score indicates that a separate adversary network had more difficulty recovering the extraneous variable.

Quantitative results across multiple benchmarks comparing ICL to standard baselines. ICL consistently achieves the lowest adversarial invariance scores (A).

Key findings include:

  • MNIST: ICL achieved an invariance score of 32, significantly outperforming the unregularized baseline (46) and MMD (55).
  • Fairness (Adult): ICL reached an adversary Mean Squared Error (MSE) of 161 when hiding the continuous variable "Age," compared to 112 for the unregularized model.
  • Medical Imaging (ADNI): ICL provided the best adversarial invariance (46) while simultaneously improving predictive accuracy for Alzheimer's disease (84% vs. 83% for the baseline).

Conclusion

ICL offers a robust, optimization-friendly alternative to adversarial training and standard mutual information regularizers. By preventing latent space collapse through inverted contrastive forces, it achieves superior invariance across both discrete and continuous extraneous variables without sacrificing predictive performance.

Summary updated

BibTeX
@inproceedings{akash2021learning,
  author = {Aditya Kumar Akash and Vishnu Suresh Lokhande and Sathya N. Ravi and Vikas Singh},
  title = {{Learning Invariant Representations using Inverse Contrastive Loss}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2021},
  doi = {10.1609/aaai.v35i8.16815},
}
Figure