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

Measuring and Improving Compositional Generalization in Text-to-SQL via Component Alignment

Yujian Gan, Xinyun Chen, Qiuping Huang, Matthew Purver

Abstract

Neural text-to-SQL models often struggle with compositional generalization, failing to interpret novel combinations of familiar linguistic and logical components. This paper introduces Spider-SS, a dataset that aligns sub-sentences with specific SQL clauses via an intermediate representation (NatSQL), and Spider-CG, a benchmark designed to evaluate performance on novel query combinations. By training models to recognize these individual components while maintaining global sentence context, the authors demonstrate significant improvements in out-of-distribution (OOD) performance, with accuracy gains of up to 37% on complex queries.

Introduction

The task of translating natural language into SQL queries has seen significant progress, yet state-of-the-art models remain brittle when faced with compositional shifts. A model may succeed on individual phrases like "names of singers" or "performed in 2014" but fail when these are combined in a previously unseen manner. This challenge, known as compositional generalization, is particularly acute in complex, cross-domain settings like the Spider benchmark.

Comparison between standard Spider SQL and the proposed Spider-SS sub-sentence alignment using NatSQL.

To address this, the authors propose a framework centered on "component alignment." By decomposing complex questions into atomic sub-sentences and mapping them to logical clauses, models can learn the fundamental building blocks of queries rather than just memorizing full-sentence patterns.

Methodology

The proposed methodology involves three key innovations:

Component Alignment via Spider-SS

The authors developed a sentence-splitting algorithm utilizing the spaCy dependency parser to break complex questions into "indivisible" sub-sentences. Each sub-sentence is manually paired with its corresponding logic using NatSQL. NatSQL serves as an intermediate representation that is syntactically closer to natural language than raw SQL, facilitating easier alignment and learning.

The Spider-CG Benchmark

To rigorously test compositional generalization, the authors created Spider-CG, a synthetic benchmark generated by recombining Spider-SS components. Two primary methods were used:

  1. Substitution: Swapping one condition for another of a similar type.
  2. Appending: Adding new conditions to increase query complexity.
Examples of Spider-SS alignment and Spider-CG compositional generalization subsets.

Context-Aware Sub-sentence Training

A critical finding of this work is the "Context Trap"—the observation that training on isolated fragments leads to a loss of necessary semantic context. The authors' solution is a training objective where the model encodes the entire sentence to preserve global context but is tasked with decoding only the specific sub-SQL clause corresponding to a highlighted sub-sentence.

Datasets

The research utilizes three primary datasets:

  • Spider: The baseline large-scale, cross-domain benchmark.
  • Spider-SS (Sub-Sentence): A new dataset of 7,000 training and 1,034 development examples split into aligned components.
  • Spider-CG (Compositional Generalization): A massive synthetic benchmark (45,599 examples) designed to evaluate OOD performance through novel combinations.

Results and Discussion

The experimental results highlight a substantial "complexity tax" in standard models, where performance drops by 10% to 30% as queries become more intricate. The component alignment approach significantly mitigates this:

  • Performance Gains: On the CG-APP subset, which tests increasingly complex appended queries, the modified RATSQL model improved from 45.2% to 82.5% accuracy.
  • Architectural Consistency: Across various state-of-the-art architectures, the sub-sentence training method provided an average improvement of 7.8% on the Spider-CG benchmark.
  • Robustness: Models trained with this method proved significantly more resilient to unseen sentence structures, even when the underlying splitting algorithm was imperfect.

Conclusion

By teaching models to recognize individual components while keeping the "big picture" in view, this research provides a scalable path toward Text-to-SQL systems that exhibit true compositional understanding. Future work will focus on expanding this methodology to other languages and refining the NatSQL conversion process to further close the performance gap.

Summary updated

BibTeX
@inproceedings{gan2022measuring,
  author = {Yujian Gan and Xinyun Chen and Qiuping Huang and Matthew Purver},
  title = {{Measuring and Improving Compositional Generalization in Text-to-SQL via Component Alignment}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2022},
  url = {https://openreview.net/forum?id=3c-jbEX-cSk},
}
Figure