Invariant Language Modeling

Maxime Peyrard, Sarvjeet Singh Ghotra, Martin Josifoski, Vidhan Agarwal, Barun Patra, Dean Carignan, Emre Kiciman, Robert West

Abstract

Large Language Models (LLMs) often rely on spurious correlations—non-causal shortcuts like data noise or societal biases—that hinder out-of-domain generalization. We present Invariant Language Modeling (iLM), a framework that adapts game-theoretic causal learning to transformer architectures. By incentivizing models to find representations that are simultaneously optimal across diverse data "environments," iLM effectively discards unstable features. Our results demonstrate that iLM achieves superior out-of-domain performance and robust bias mitigation with minimal computational overhead.

Introduction

Modern language models typically employ Empirical Risk Minimization (ERM), which minimizes average loss across a training set. However, this approach often leads models to exploit "spurious correlations"—statistical shortcuts that do not represent fundamental linguistic rules. For instance, a model might associate "doctor" with masculine pronouns simply because of frequency in the training data. This reliance on shortcuts results in poor generalization to new domains, sensitivity to formatting noise (like HTML tags), and the amplification of societal biases.

To address these issues, we propose moving toward causal machine learning through the Invariance Principle. This principle posits that a relationship is only worth learning if it remains stable across various "environments," such as different genres or sources of text.

Methodology: Invariant Language Modeling (iLM)

The iLM framework adapts Invariant Risk Minimization (IRM) games to the transformer architecture. Unlike standard training (eLM), which treats all data as a single pool, iLM partitions data into distinct environments.

The iLM framework uses a latent causal model to distinguish stable features from spurious ones across different environments.

The architecture utilizes multiple environment-specific "heads" sharing a common transformer encoder "body." Training proceeds in a round-robin fashion where each head is updated to minimize local loss for its specific environment, while the shared encoder is updated to provide a representation that is optimal for all heads simultaneously. This competitive setup forces the encoder to ignore features that are only predictive in specific environments (spurious noise) and retain those that are universally predictive (stable, causal features).

Experimental Setup

We evaluated iLM across several benchmarks:

  • Noise Robustness: Comparing clean Wikipedia text against raw HTML to test the model's ability to ignore structural artifacts.
  • Bias Mitigation: Using Wikitext-2 and Counterfactual Data Augmentation (CDA) to create balanced and unbalanced gendered datasets.
  • Generalization: Training on 11 domains of ThePile (e.g., ArXiv, GitHub) and testing on 9 unseen domains (e.g., OpenSubtitles).
  • Downstream Performance: Validating on the GLUE benchmark to ensure core linguistic capabilities remain intact.

Key Results and Discussion

iLM demonstrated significant improvements in robustness and generalization. In noise-heavy environments, iLM achieved lower perplexity on clean text compared to standard models (4.43 vs. 4.71 for DistilBERT), indicating it successfully filtered out "junk" formatting.

iLM maintains low bias even when the fair data environment is significantly smaller than the biased one, unlike standard eLM.

A critical finding is iLM's efficiency in bias removal. As shown in Figure 2, iLM maintains a low bias score even when the "unbiased" environment constitutes only 10% of the training data. In contrast, standard eLM requires a perfectly balanced 50/50 split to achieve comparable fairness. This suggests that in iLM, data diversity acts as a tool rather than a challenge; the more distinct the environments, the more effectively the model identifies invariant features.

On unseen domains from ThePile, iLM consistently outperformed baselines. For example, RoBERTa trained with iLM reached an out-of-domain perplexity of 16.97, compared to 17.72 for the standard approach. These gains are achieved with negligible additional computational cost.

Conclusion

Invariant Language Modeling provides a scalable path toward more robust and fair AI. By shifting the focus from simple loss minimization to cross-environment stability, iLM reduces the reliance on spurious shortcuts. Future work will explore automated environment discovery to further optimize the selection of data splits and investigate the scaling properties of iLM in larger models.

Summary updated

Abstract

Modern pretrained language models are critical components of NLP pipelines. Yet, they suffer from spurious correlations, poor out-of-domain generalization, and biases. Inspired by recent progress in causal machine learning, in particular the invariant risk minimization (IRM) paradigm, we propose invariant language modeling, a framework for learning invariant representations that generalize better across multiple environments. In particular, we adapt a game-theoretic implementation of IRM (IRM-games) to language models, where the invariance emerges from a specific training schedule in which all the environments compete to optimize their own environment-specific loss by updating subsets of the model in a round-robin fashion. In a series of controlled experiments, we demonstrate the ability of our method to (i) remove structured noise, (ii) ignore specific spurious correlations without affecting global performance, and (iii) achieve better out-of-domain generalization. These benefits come with a negligible computational overhead compared to standard training, do not require changing the local loss, and can be applied to any language model architecture. We believe this framework is promising to help mitigate spurious correlations and biases in language models.
BibTeX
@inproceedings{peyrard2022invariant,
  author = {Maxime Peyrard and Sarvjeet Singh Ghotra and Martin Josifoski and Vidhan Agarwal and Barun Patra and Dean Carignan and Emre Kiciman and Robert West},
  title = {{Invariant Language Modeling}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  doi = {10.18653/v1/2022.emnlp-main.387},
}
Figure