Bayesian Invariant Risk Minimization

Yong Lin, Hanze Dong, Hao Wang, Tong Zhang

Machine learning models often rely on spurious correlations—patterns that exist in the training data but do not hold in the real world. For instance, a model might learn to identify a "cow" based on a grassy background rather than the animal's features. When tested in a different environment (e.g., a cow on a beach), such models fail. Invariant Risk Minimization (IRM) was designed to solve this by finding features that lead to a stable classifier across different training environments. However, IRM frequently fails when applied to deep neural networks. This paper introduces Bayesian Invariant Risk Minimization (BIRM) to address a fundamental flaw in standard IRM: the "Overfitting Pitfall."

The Overfitting Pitfall in IRM

The core idea of IRM is to find a representation such that the optimal classifier on top of it is the same across all environments. This is enforced via a mathematical penalty. However, deep neural networks have high capacity, allowing them to perfectly memorize training data. The authors demonstrate that as a model overfits, the IRM penalty vanishes even if the model continues to rely on spurious features.

The Overfitting Pitfall: As iterations increase, the IRM penalty drops to near zero while the non-invariant indicator (reliance on spurious features) remains high, especially for larger models.

As shown in the figure above, the IRM penalty quickly decays to zero. Meanwhile, the "non-invariant indicator"—a metric measuring reliance on spurious shortcuts—remains high (around 70-80%). This suggests the model "cheats" the IRM objective by memorizing data points, effectively making the invariance constraint toothless.

Bayesian Invariant Risk Minimization (BIRM)

To combat this, the authors propose BIRM. Instead of seeking a single optimal point estimate for the classifier, BIRM considers the posterior distribution of classifiers for each environment.

  1. Invariance via Posteriors: If a representation is truly invariant, the posterior distribution of the classifier should be consistent across all environments. Distributions are much harder to "fake" through memorization than single points, ensuring the penalty remains informative even during overfitting.
  2. Variance Reduced Reparameterization: Training with distributions can be noisy. BIRM uses a sampling trick with shared random noise across environments to stabilize the learning signal.
  3. Fast Adaptation: To maintain computational efficiency, the authors use a "Fast Adaptation" method (similar to MAML) to approximate environment-specific posteriors with a single gradient step.

Experimental Results

The authors evaluated BIRM against standard Empirical Risk Minimization (ERM) and several IRM variants (IRMv1, REx, InvRat) across four benchmarks: Synthetic, Colored MNIST (CMNIST), ColoredObject, and CifarMnist.

BIRM consistently demonstrated superior performance and robustness. Notably, while standard IRM methods often perform worse as model capacity (hidden dimension) increases—due to exacerbated overfitting—BIRM remains stable or improves.

Comparison of test accuracy across different training data sizes and model capacities. BIRM (blue) consistently outperforms baselines and maintains stability as the hidden dimension increases.

Key Findings:

  • Data Efficiency: In low-data regimes (e.g., 5,000 samples for CMNIST), BIRM achieved 60.01% accuracy, whereas the next best baseline, REx, dropped to 32.55%.
  • Robustness to Model Size: As seen in the figure above, BIRM's accuracy does not degrade with larger hidden dimensions, unlike IRMv1 or InvRat, which show significant performance drops in low-data settings as they overfit.
  • Benchmark Performance: BIRM achieved state-of-the-art results on ColoredObject (78.1%) and CifarMnist (59.3%), significantly outperforming existing invariant learning techniques.

Conclusion

BIRM provides a robust framework for out-of-distribution generalization by moving from point-based invariance to distribution-based invariance. By leveraging Bayesian posteriors, it successfully avoids the "Overfitting Pitfall" that plagues standard IRM, making it a more reliable choice for deep learning applications where environmental shifts are expected. While it introduces some additional computational overhead, its data efficiency and stability across model architectures represent a significant step forward in causal and invariant machine learning.

Summary updated

BibTeX
@inproceedings{lin2022bayesian,
  author = {Yong Lin and Hanze Dong and Hao Wang and Tong Zhang},
  title = {{Bayesian Invariant Risk Minimization}},
  booktitle = {IEEE/CVF Conference on Computer Vision and Pattern Recognition},
  year = {2022},
  doi = {10.1109/cvpr52688.2022.01555},
}
Figure