Abstract
In-context learning has shown great success in i.i.d semantic parsing splits, where the training and test sets are drawn from the same distribution. In this setup, models are typically prompted with demonstrations that are similar to the input utterance. However, in the setup of compositional generalization, where models are tested on outputs with structures that are absent from the training set, selecting similar demonstrations is insufficient, as often no example will be similar enough to the input. In this work, we propose a method to select diverse demonstrations that aims to collectively cover all of the structures required in the output program, in order to encourage the model to generalize to new structures from these demonstrations. We empirically show that combining diverse demonstrations with in-context learning substantially improves performance across three compositional generalization semantic parsing datasets in the pure in-context learning setup and when combined with finetuning.
The Challenge of Compositional Generalization
Large Language Models (LLMs) have demonstrated remarkable capabilities in semantic parsing—the task of mapping natural language to formal logic or code. However, they frequently stumble on "compositional generalization," where a test query requires a novel combination of structures that the model has seen individually but never in that specific arrangement.
The standard paradigm for in-context learning (ICL) relies on similarity-based retrieval (e.g., Top-K), where the prompt is populated with training examples most similar to the input question. This research identifies a fundamental flaw in this approach for compositional tasks: similar examples are often redundant. If a target program requires three distinct sub-structures, but the most "similar" examples only demonstrate one of them, the model lacks the necessary building blocks to construct the correct output.
Methods: From Similarity to Structural Coverage
To address this, the authors propose Cover-LS (Coverage of Local Structures), a framework that shifts the focus from individual similarity to collective coverage. The process involves three key steps:
- Predict Local Structures: An auxiliary model (such as T5) predicts the "local structures" (small sub-trees of the program) likely to appear in the target output.
- Iterative Selection: The algorithm greedily selects training examples that collectively cover as many of these predicted structures as possible.
- Prioritize Complexity: By selecting examples that cover larger, more complex sub-trees first, the prompt provides a richer context for the model to learn composition.
For scenarios where program prediction is unreliable, a variant called Cover-Utt is used, which selects examples to cover the specific words in the input utterance instead of structural sub-trees.
Empirical Evaluation and Results
The researchers evaluated these methods on three major benchmarks: GeoQuery, SMCalFlow-CS, and COVR-10. The results demonstrate that diversity-based selection is significantly more effective than standard retrieval methods.
Key findings include:
- Significant Accuracy Gains: On the SMCalFlow-CS split, Cover-LS improved exact match accuracy from 50.3% to 73.5% compared to the Top-K baseline.
- High Sample Efficiency: Diverse prompts are remarkably efficient; Cover-LS with just 4 demonstrations often matches the performance of similarity-based prompting using 24 demonstrations.
- Robustness: The method outperformed much larger models (like PaLM 540B) that relied on standard BM25 retrieval, proving that the logic of the prompt selection is more critical than the raw scale of the model.
Conclusion
This work demonstrates that for complex reasoning and semantic parsing, the set of demonstrations in a prompt should act as a comprehensive "toolbox." By ensuring that the prompt collectively covers the required structural components, models can effectively compose novel solutions. This shift from similarity to diversity is a vital step toward achieving robust compositional generalization in LLMs.
Summary updated