NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Learning to Substitute Components for Compositional Generalization

Zhaoyi Li, Gangwei Jiang, Chenwang Wu, Ying Wei, Defu Lian, Enhong ChenarXiv 2025 · OpenReview

Abstract

Despite the rising prevalence of neural language models, recent empirical evidence suggests their deficiency in compositional generalization. One of the current de-facto solutions to this problem is compositional data augmentation, which aims to introduce additional compositional inductive bias. However, existing handcrafted augmentation strategies offer limited improvement when systematic generalization of neural language models requires multi-grained compositional bias or when training sentences have an imbalanced difficulty distribution. To address these challenges, we first propose a novel compositional augmentation strategy called Component Substitution (CompSub), which enables multi-grained composition of substantial substructures across the entire training set. Furthermore, we introduce the Learning Component Substitution (LCS) framework. This framework empowers the learning of component substitution probabilities in CompSub in an end-to-end manner by maximizing the loss of neural language models, thereby prioritizing challenging compositions with elusive concepts and novel contexts. We extend the key ideas of CompSub and LCS to the recently emerging in-context learning scenarios of pre-trained large language models (LLMs), proposing the LCS-ICL algorithm to enhance the few-shot compositional generalization of state-of-the-art (SOTA) LLMs. Empirically, our results on four standard compositional generalization benchmarks (SCAN, COGS, GeoQuery, and COGS-QL) demonstrate the superiority of CompSub, LCS, and LCS-ICL, with improvements of up to 66.5%, 10.3%, 1.4%, and 8.8%, respectively.

Introduction: The Compositional Gap

While modern AI can write poetry and code, it often stumbles on simple logic. If a model learns "jump twice" and "walk around the room," it might still fail to understand "jump around the room twice." This is a failure of compositional generalization: the ability to produce and understand an infinite number of novel combinations from known components.

Existing solutions usually involve "data augmentation"—creating new training examples by swapping words. However, these methods are often "handcrafted" and limited. They might only swap single words (lexical) or specific tree structures (structural), missing the "middle ground" of complex phrases. Furthermore, they treat all new examples as equally useful, even though some combinations are much harder for a model to learn than others.

Methodology: Multi-Grained and Adversarial Augmentation

Component Substitution (CompSub)

The authors propose CompSub, a flexible augmentation strategy that identifies "eligible spans"—consecutive fragments of text that are semantically self-contained. It then swaps these spans across the training set based on syntactic equivalence (e.g., swapping one noun phrase for another). Unlike previous methods, it works across multiple "grains," from single words to complex sub-clauses.

Figure 1: Examples of word-level and subtree-level composition through component substitution.

Learning Component Substitution (LCS)

LCS is the "smart" version of CompSub. Instead of swapping parts at random, it uses a differentiable "augmenter" model. This augmenter is trained to maximize the loss of the main model. In other words, it acts as an adversary, specifically searching for the "blind spots" and difficult combinations that the model currently doesn't understand. This ensures the model is exposed to the most informative training signals.

Figure 5: The Learning Component Substitution (LCS) framework, featuring an adversarial augmenter that selects challenging spans to maximize model loss.

LCS-ICL for Large Language Models

The authors extend this logic to In-Context Learning (ICL) for Large Language Models (LLMs). Instead of giving an LLM random examples in its prompt, LCS-ICL selects the most "informative" (difficult) augmented examples to help the LLM grasp tricky compositional rules on the fly.

Evaluation and Results

The framework was evaluated on four major benchmarks designed to test compositional limits:

  • SCAN: A navigation task testing simple rule following and length generalization.
  • COGS: A synthetic dataset mapping English sentences to logical forms, testing linguistic abstractions.
  • GeoQuery: A real-world dataset of natural language questions about US geography.
  • COGS-QL: A version of COGS tailored for testing the in-context learning abilities of LLMs.

The proposed methods achieved significant performance leaps over previous state-of-the-art (SOTA) techniques:

  • SCAN: Improved accuracy by up to 66.5% on the challenging "length" split.
  • COGS: Boosted performance by 10.3%, effectively handling complex linguistic transformations.
  • GeoQuery: Achieved a 1.4% improvement, reaching near-perfect scores on several splits.
  • LLMs (LCS-ICL): When applied to LLaMA-3-8B, the method outperformed the best existing prompting baselines by 8.8% on the COGS-QL task.

Key Insights and Discussion

  • Difficulty Awareness: Randomly swapping words is helpful, but specifically generating "hard" examples is much more efficient. By acting as an adversary, the LCS augmenter prioritizes elusive concepts and novel contexts.
  • Multi-Grained Flexibility: By focusing on "spans" rather than just words or rigid subtrees, CompSub can capture a wider variety of linguistic structures, making the model's understanding more "fluid."
  • Implicit Regularization: Mathematically, CompSub acts as a form of regularization. It forces the model to learn "semantic invariance"—the idea that the meaning of a component (like "the cat") should remain stable regardless of the complex sentence structure surrounding it.

Limitations

The authors note that their "exchangeability" rule—which determines if one span can replace another based on their first and last tokens—is a heuristic. While effective, it might occasionally produce linguistically awkward sentences. Future work could involve more sophisticated ways to define "eligible spans" using deeper semantic analysis or applying these principles to multi-modal domains.

Summary updated

BibTeX
@misc{li2025learning,
  author = {Zhaoyi Li and Gangwei Jiang and Chenwang Wu and Ying Wei and Defu Lian and Enhong Chen},
  title = {{Learning to Substitute Components for Compositional Generalization}},
  year = {2025},
  eprint = {2502.20834},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2502.20834},
}
Figure