SQL-GEN: Bridging the Dialect Gap for Text-to-SQL Via Synthetic Data And Model Merging

Mohammadreza Pourreza, Ruoxi Sun, Hailong Li, Lesly Miculicich, Tomas Pfister, Sercan Ö. Arik · DOI

Abstract

While Large Language Models (LLMs) have become remarkably proficient at translating natural language into SQL, they suffer from a significant "dialect gap." Most research and benchmarks focus on SQLite, whereas enterprise environments rely on a diverse landscape of engines like BigQuery and PostgreSQL. This paper introduces SQL-GEN, a framework designed to bridge this gap through high-quality synthetic data generation and a novel model-merging strategy. SQL-GEN leverages dialect-specific tutorials to boost execution accuracy by up to 20% and utilizes a Mixture-of-Experts (MoE) architecture to create a single, versatile engine that outperforms single-dialect specialists.

Introduction

The "dialect gap" is a major hurdle for real-world Text-to-SQL systems. Human-annotated datasets like Spider or BIRD are expensive to produce and predominantly target SQLite. Automated transpilation to other dialects is error-prone—failing roughly 20% of the time—and often misses engine-specific optimizations. SQL-GEN addresses two core challenges: the scarcity of high-quality training data for diverse dialects and the inefficiency of deploying separate massive LLMs for each engine.

Methodology

The SQL-GEN Pipeline

The authors propose a three-stage synthetic data generation process that prioritizes dialect accuracy:

  1. Template Expansion: The process begins with simple "seed" SQL templates. An LLM expands these into complex queries using dialect-specific tutorials scraped from the web, ensuring the model learns the correct syntax and unique functions of the target engine.
  2. Template Filling: These abstract templates are populated with actual schema elements and values from real-world databases.
  3. Quality Control: To maintain high data standards, a secondary LLM acts as a "judge" alongside execution-based filtering. Queries that fail to run or do not match the natural language intent are discarded.
The SQL-GEN pipeline for synthetic data generation, from template extraction to final dataset creation.

Multi-Dialect MoE Merging

To unify these capabilities without redundant parameters, SQL-GEN employs a Mixture-of-Experts (MoE) architecture. Instead of training from scratch, the framework merges existing dialect-specific models:

  • SLERP Merging: Spherical Linear Interpolation (SLERP) is used to merge the self-attention layers of different models, preserving the geometric properties of the weight space.
  • Expert Gate Initialization: To prevent "expert collapse," router gates are initialized using the hidden states of dialect-specific keywords (e.g., SAFE for BigQuery). This "primes" the model to route specific tokens to the appropriate dialect expert.
The proposed MoE architecture featuring SLERP merging and keyword-based router initialization.

Evaluation and Results

The framework was evaluated across several benchmarks, including BIRD (SQLite), Pagila (PostgreSQL), and a real-world GitHub Repositories dataset (BigQuery).

  • Accuracy Boost: SQL-GEN improved execution accuracy by up to 20% over existing synthetic data methods like Gretel.
  • Generalization: On the BigQuery-specific GitHub dataset, the SQL-GEN model outperformed the next best baseline by 10%.
  • Synergy: Combining SQL-GEN synthetic data with human-annotated data yielded an additional 5.6% improvement, proving its value as a powerful data augmentation tool.
  • MoE Superiority: The merged MoE model outperformed single-dialect models and other merging techniques (like DARE or TIES) by an average of 2.5%, reaching up to 7.3% improvement in some cases.

Discussion and Conclusion

SQL-GEN demonstrates that using online documentation as a prompt for synthetic generation allows LLMs to "self-teach" new syntax effectively. Furthermore, keyword-driven routing provides a structural understanding of which "expert" to consult for specific dialects. While the framework significantly mitigates the dialect gap, future work will focus on refining MoE routing to handle shared SQL syntax more efficiently and extending the logic to cross-lingual Text-to-SQL tasks.

Summary updated

BibTeX
@misc{pourreza2024sql,
  author = {Mohammadreza Pourreza and Ruoxi Sun and Hailong Li and Lesly Miculicich and Tomas Pfister and Sercan Ö. Arik},
  title = {{SQL-GEN: Bridging the Dialect Gap for Text-to-SQL Via Synthetic Data And Model Merging}},
  year = {2024},
  eprint = {2408.12733},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.12733},
}
Figure