Invariant Language Modeling

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

TL;DR

The paper introduces Invariant Language Modeling (iLM), a training framework that forces models to ignore "spurious correlations"—statistical shortcuts that don't generalize—by learning features that remain stable across different data environments. By adapting game-theoretic Invariant Risk Minimization (IRM-games) to the transformer architecture, the authors demonstrate improved out-of-domain generalization and more robust bias removal with negligible computational overhead.

What Problem Does This Paper Address?

Modern Large Language Models (LLMs) are incredibly powerful, but they are "lazy" learners. During standard training (Empirical Risk Minimization, or ERM), they often latch onto spurious correlations: patterns that happen to exist in the training data but aren't true causal or structural relationships.

For example, if a training set frequently mentions "doctor" alongside "he," a model might learn a gender bias as a statistical shortcut for prediction. When that model encounters a different distribution (e.g., a dataset where "doctor" is neutral or associated with "she"), its performance tanks. This leads to poor out-of-domain (OoD) generalization and the amplification of societal biases. Existing fixes often require expensive domain alignment or manual "de-biasing" of datasets, which is difficult to scale.

Methods

The authors propose iLM, which shifts the goal from "minimize average error" to "find representations that are simultaneously optimal across different environments."

The Invariance Principle

The core idea is that while noise and spurious correlations change across environments (e.g., Wikipedia vs. Twitter), the fundamental structure of language (grammar, logic, common sense) remains invariant.

iLM Architecture & "IRM-Games"

  1. Environment Splitting: The training data is partitioned into $n$ environments (e.g., by source, topic, or style).
  2. Shared Body, Multiple Heads: The model consists of a shared transformer encoder ($\phi$) and $n$ environment-specific language modeling heads ($w_e$).
  3. The Training "Game": Instead of updating everything at once, the environments play a game. In a round-robin fashion:
  4. A batch is taken from Environment A.
  5. The model calculates a loss based on an ensemble of all $n$ heads.
  6. Only the shared body ($\phi$) and the specific head for Environment A ($w_A$) are updated.
  7. The Result: To win this "game," the shared body must extract features that are useful for all heads at once. Features that only help one environment (the spurious ones) are eventually discarded because they hinder the ensemble's performance in other environments.

Datasets

The authors conducted controlled experiments using:

  • Wikipedia (Clean vs. HTML): Used to test robustness to structured noise. One environment was clean text; the other was raw HTML-heavy Wikipedia dumps.
  • Wikitext-2: Used for gender bias experiments. They used Counterfactual Data Augmentation (CDA) to create "balanced" and "unbalanced" gendered environments.
  • The Pile: A massive, diverse dataset. They used 11 domains (e.g., ArXiv, PubMed, GitHub) for training and 9 unseen domains for testing OoD generalization.
  • GLUE Benchmark: Used to evaluate how iLM-trained models perform on downstream NLP tasks.

Key Insights and Ideas

  • Environment Design as a Lever: The authors argue that we don't need to know the exact causal graph of language. Instead, by choosing how we split our data into "environments," we can implicitly tell the model which correlations to ignore.
  • Robustness to Unbalanced Data: Standard de-biasing (like CDA) only works if you have a perfectly 50/50 split of biased and unbiased data. iLM is much more robust; it can effectively remove bias even if the "unbiased" environment is only 10% of the total training data.
  • Latent Invariance: iLM doesn't just look at surface-level word overlaps. In a fascinating experiment using English and Farsi as two environments, the model still improved, proving it learns invariant features in the latent representation space rather than just matching keywords.

Key Results

  • Noise Robustness: iLM achieved significantly lower perplexity on clean test data compared to standard models (eLM) when trained on noisy data.
  • Bias Removal: In gender-bias tests, iLM outperformed standard training by a wide margin in "unbalanced" scenarios. It achieved the same level of bias reduction with 10% of the data that standard methods required 100% of the data to achieve.
  • Generalization: On "The Pile," iLM showed superior generalization to unseen domains. It also led to better performance on the GLUE benchmark (specifically for RoBERTa), showing that invariant pre-training helps downstream tasks.
  • Efficiency: The method adds almost no extra time or memory cost compared to standard training, making it a "free lunch" for model robustness.

Limitations and Future Work

  • The "How to Split" Problem: While iLM is powerful, it relies on having a good strategy for defining environments. The authors note that "environment design" is a new challenge: how do we automatically find the best splits for a specific task?
  • Scale: The experiments were performed on relatively small models (distilBERT and RoBERTa). The authors acknowledge that the "emergent properties" of massive models (like GPT-4) might change how invariance behaves.
  • Downstream Sensitivity: While iLM improved GLUE scores, the gains were more modest than the improvements in raw language modeling (perplexity). Future work is needed to see how to better translate invariant representations into specific task performance.

Summary updated

Abstract

Large pretrained language models are critical components of modern 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 formulation 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. We focus on controlled experiments to precisely 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. 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