CCL: Causal-aware In-context Learning for Out-of-Distribution Generalization

Hoyoon Byun, Gyeongdeok Seo, Joonseong Kang, Taero Kim, Jihee Kim, Kyungwoo SongNeurIPS 2025

TL;DR

Traditional in-context learning (ICL) often fails when a query looks different from the provided examples, even if the underlying logic is the same. This paper introduces Causal-aware In-context Learning (CCL), a method that selects demonstrations based on shared causal logic rather than surface-level similarity, significantly improving how Large Language Models (LLMs) generalize to out-of-distribution (OOD) data.

What Problem Does This Paper Address?

In-context learning (ICL) has become the standard way to prompt LLMs: you provide a few examples (demonstrations) in the prompt, and the model follows the pattern to answer a new query. However, LLMs are notorious for latching onto "superficial patterns"—keywords, specific phrasing, or formatting—rather than the actual task logic.

This becomes a major hurdle in Out-of-Distribution (OOD) scenarios. For example, imagine your target query is a math problem about bananas. A traditional ICL retriever might mistakenly pick a sentiment analysis example from the demonstration pool just because the word "bananas" appears in both. It relies on the "Space of $x$" (raw input features), leading to poor choices.

As shown in the figure below, CCL instead maps inputs to a "Space of $c$" (causal logic). By doing so, it correctly identifies that a seemingly unrelated math problem about game survivors shares the exact same underlying mathematical relationship ($N - M = K$) as the banana query.

Comparison between traditional ICL (matching surface features in Space of x) and CCL (matching causal logic in Space of c).

Methods

The authors propose a two-phase framework called CCL to move beyond surface-level matching:

  1. Phase 1: Causal Representation Learning: Using an in-distribution dataset, the authors train a novel Variational Autoencoder (VAE) to disentangle the data into two distinct latent variables:
  2. $c$ (Causal Variable): Represents the fundamental task logic (e.g., the mathematical operation $N - M = K$). This is designed to be invariant across different environments.
  3. $s$ (Source Variable): Captures domain-specific or environmental features (e.g., the language used, the specific nouns in the word problem).
  4. Phase 2: Causal-aware Selection: When a new query arrives, the system uses the trained encoder to find its causal representation ($c^*$). It then selects demonstrations from the training pool that have the most similar causal features. This ensures the LLM sees examples that solve the same problem, even if the surface-level text looks entirely different.

This approach is supported by a theoretical analysis proving that selecting examples based on causal similarity ($c$) leads to tighter error bounds and more robust predictions than selecting based on input similarity ($x$).

Datasets

The researchers evaluated CCL across several challenging setups to test OOD generalization:

  • Synthetic Data: A controlled environment with three tasks and five environments to verify if the model could truly separate task logic from environmental noise.
  • MGSM (Multilingual Grade School Math): A benchmark of math problems translated into ten languages. They used some languages for training (In-Distribution) and others like Swahili, Thai, and Bengali for testing (OOD).
  • OOD NLP Benchmarks: Standard tasks including QNLI (Natural Language Inference), PIQA (Physical Commonsense Reasoning), WSC273 (Winograd Schema Challenge), and YELP (Sentiment Analysis).

Key Insights and Ideas

  • Invariance is Key: The core realization is that while the style of a prompt changes across distributions, the causal mechanism generating the answer remains the same. By forcing the VAE to reconstruct the answer ($y$) only from the causal variable ($c$), the model learns to ignore distracting environmental noise ($s$).
  • Provable Robustness: The paper mathematically demonstrates that "input proximity" can be deceptive. Two points can be very close in standard feature space but require completely different labels. Causal similarity avoids this trap.
  • Disentanglement Works: Qualitative analysis showed that by zeroing out the $s$ variable, the model could isolate the "intent" of a sentence (e.g., "negative sentiment") regardless of the specific objects or entities mentioned.

Key Results

CCL consistently outperformed traditional ICL and other advanced retrieval baselines:

  • Math Reasoning (MGSM): On OOD languages, CCL improved retrieval accuracy from 53.00% to 61.52% compared to standard embedding-based methods.
  • General NLP Benchmarks: When using the Llama-3.2-3B-IT model, CCL achieved an average OOD accuracy of 75.74%, a massive jump over the zero-shot baseline (64.75%) and standard K-means ICL (65.70%).
  • Model Agnostic: The benefits held true across different model sizes, including Phi-4-mini and GPT-4o, though the gains were most pronounced for smaller, more sensitive models.

Limitations and Future Work

The authors identify a few areas for improvement:

  • VAE Limitations: The structural assumptions of VAEs might limit their ability to capture the full complexity and nuance of natural language compared to massive transformer-based encoders.
  • Retrieval Integration: While CCL improves selection, the authors suggest that deeper integration between the causal embedding process and the retrieval mechanism itself could yield even better results.
  • Complexity: Training the VAE-based causal model adds an extra step to the pipeline, which might be a hurdle for simple "plug-and-play" applications.

Summary updated

BibTeX
@inproceedings{byun2025ccl,
  author = {Hoyoon Byun and Gyeongdeok Seo and Joonseong Kang and Taero Kim and Jihee Kim and Kyungwoo Song},
  title = {{CCL: Causal-aware In-context Learning for Out-of-Distribution Generalization}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=FxV7Fvlm2T},
}
Figure