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 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.
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