Diverse Parallel Data Synthesis for Cross-Database Adaptation of Text-to-SQL Parsers

Abhijeet Awasthi, Ashutosh Sathe, Sunita Sarawagi

Introduction

Text-to-SQL parsing—the task of translating natural language questions into executable SQL queries—is a critical component for making databases accessible to non-technical users. However, state-of-the-art parsers often struggle with "cross-database" generalization. When presented with a database schema not seen during training, these models frequently fail or "hallucinate," as they are unable to map user intent to unfamiliar table and column names.

The traditional solution involves synthesizing training data for the new target database. Yet, conventional SQL-to-Text generation methods often produce repetitive, template-like questions that lack the linguistic variety of real-world human queries. This "robotic" synthetic data can bias the parser, making it brittle when faced with diverse phrasing. To address this, we present REFILL, a framework that leverages a "Retrieve-and-Edit" strategy to generate high-quality, diverse parallel data for cross-database adaptation.

The REFILL Framework

REFILL departs from standard generative approaches by repurposing existing human-written queries from source datasets (like Spider) to fit the schema of a new target database. This process ensures that the synthesized text retains the complexity and naturalness of human speech.

The REFILL framework pipeline: Retrieval, Masking, Editing, and Filtering.

The REFILL pipeline consists of four primary stages:

  1. Retrieval: For a given target SQL query, REFILL identifies structurally similar queries in a source dataset using Tree Edit Distance (TED). This step ensures that the retrieved natural language text provides a linguistically sound starting point.
  2. Frequency-based Masking: To generalize the retrieved text, REFILL identifies and masks schema-specific terms. Unlike simple string matching, REFILL uses word frequency across multiple databases to distinguish between common functional words (e.g., "show", "count") and domain-specific entities (e.g., "stadiums", "players").
  3. Edit and Fill: A modified BART model is employed to fill the masked templates. It takes the target SQL and the masked text as input to generate a new natural language query tailored to the target database. A robust training strategy allows the model to handle noisy or missing templates effectively.
  4. Independent Filtering: To maintain high data quality, synthesized pairs are passed through a binary classifier. Crucially, this filter is independent of the parser being trained, avoiding the "cycle-consistency trap" where a model only learns from data it already understands.

Experimental Results

REFILL was evaluated on the Spider benchmark and four additional cross-domain datasets (GeoQuery, Academic, IMDB, and Yelp). The results demonstrate that REFILL significantly outperforms existing data synthesis baselines.

Accuracy and Generalization

As shown in the table below, REFILL consistently improves performance across various database groups, achieving an average gain of 8.0% in Exact Match (EM) accuracy over the base model. It notably excels in more complex scenarios (Groups 2-4), where structural diversity is paramount.

Performance comparison of REFILL against various baselines across different database groups.

Efficiency and Diversity

Beyond raw accuracy, REFILL proves to be highly efficient. Experiments revealed that REFILL using only 30% of a target SQL workload could outperform competitive baselines that utilized 70% of the same workload. This suggests that the quality and diversity of the synthesized data are more impactful than sheer volume.

Linguistic diversity was measured using the SelfBLEU metric (where lower scores indicate higher diversity). REFILL achieved a diversity score of 33.8, a massive improvement over standard SQL-to-Text baselines which typically score around 2.0. This confirms that REFILL successfully captures the varied ways humans phrase questions, providing a more robust training signal for the parser.

Conclusion

REFILL addresses a fundamental bottleneck in Text-to-SQL parsing: the lack of diverse, high-quality training data for new domains. By shifting from scratch-based generation to a retrieve-and-edit paradigm, REFILL produces synthetic data that is both structurally accurate and linguistically rich. While currently optimized for SQL, the underlying logic of REFILL holds promise for other semantic parsing tasks, such as code generation, where adapting to new APIs or libraries remains a significant challenge.

Summary updated

BibTeX
@inproceedings{awasthi2022diverse,
  author = {Abhijeet Awasthi and Ashutosh Sathe and Sunita Sarawagi},
  title = {{Diverse Parallel Data Synthesis for Cross-Database Adaptation of Text-to-SQL Parsers}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2022},
  url = {https://openreview.net/forum?id=LyuAngwjTX},
}
Figure