SQL-PaLM: Improved Large Language Model Adaptation for Text-to-SQL

Ruoxi Sun, Sercan Ö. Arik, Hootan Nakhost, Hanjun Dai, Rajarishi Sinha, Pengcheng Yin, Tomas PfisterarXiv 2023 · DOI

Abstract

SQL-PaLM is a holistic framework designed to adapt the PaLM-2 large language model (LLM) for the Text-to-SQL task. By integrating advanced instruction fine-tuning, execution-based consistency decoding, and intelligent schema selection, SQL-PaLM addresses the inherent challenges of human language ambiguity and database complexity. The framework achieves state-of-the-art results on major benchmarks, including 87.3% execution accuracy on Spider and 61.7% on BIRD, demonstrating significant improvements in handling massive real-world databases and complex reasoning.

Introduction

Translating natural language questions into valid SQL queries—the Text-to-SQL task—is a critical bridge between non-technical users and large-scale data. Despite the promise of Large Language Models (LLMs), several real-world hurdles persist. Large databases often feature hundreds of tables and thousands of columns, exceeding the context window of most models. Furthermore, human language is frequently ambiguous, and complex queries require multi-step reasoning and domain-specific knowledge. LLMs also suffer from the "lost in the middle" phenomenon, where relevant information is overlooked when buried in extensive database schemas.

Example of a Text-to-SQL task where a natural language question is translated into a complex SQL query involving joins and set operations.

Methods

SQL-PaLM addresses these challenges through a multi-faceted approach involving both prompting strategies and fine-tuning regimes.

Execution-based Consistency Decoding

During inference, the model generates multiple potential SQL queries. These queries are executed against the database, and the result that appears most frequently (excluding errors) is selected. This "execution-based selection" leverages the database itself as a validator to filter out syntactically correct but logically incorrect queries.

Instruction Fine-Tuning and Data Augmentation

The PaLM-2 "Unicorn" model is fine-tuned on a diverse mixture of Text-to-SQL data. To increase training diversity, the framework employs Synthetic Data Augmentation, using an LLM to generate multiple correct SQL variations for the same natural language question. Additionally, Database Context Integration injects actual database values into prompts, helping the model map user terms (e.g., "Alameda County") to specific database entries (e.g., "Alameda").

Schema Selection

To manage massive schemas, SQL-PaLM utilizes two primary techniques:

  1. Retrieval-based Selection: Using embeddings to identify the most relevant columns.
  2. Program-aided Selection: Utilizing a preliminary SQL query from a smaller model to pinpoint necessary columns.
The SQL-PaLM framework overview, including data diversification, synthetic data generation, database context integration, column selection, and execution-based selection.

Results and Insights

SQL-PaLM set new performance records across industry-standard benchmarks:

  • Spider: Achieved 87.3% Execution Accuracy, surpassing specialized models like RESDSQL and prompting-only methods using GPT-4.
  • BIRD: Achieved 61.7% Execution Accuracy, a substantial improvement over previous state-of-the-art methods (54-57%).
  • Robustness: On the Spider-DK variant, which requires domain knowledge, SQL-PaLM maintained a high performance of 66.5%.

Key insights from the study include the importance of scaling; the larger PaLM-2 Unicorn model significantly outperformed smaller variants on complex reasoning. Furthermore, mixing diverse datasets during fine-tuning proved essential for handling distribution shifts in unseen database types.

Conclusion

SQL-PaLM demonstrates that a holistic approach—combining intelligent context management, execution feedback, and diverse fine-tuning—can significantly bridge the gap between natural language and structured data. While challenges remain regarding ground-truth errors in benchmarks and the "lost in the middle" effect in extremely large schemas, SQL-PaLM provides a robust foundation for future research in automated data interaction.

Summary updated

BibTeX
@misc{sun2023sql,
  author = {Ruoxi Sun and Sercan Ö. Arik and Hootan Nakhost and Hanjun Dai and Rajarishi Sinha and Pengcheng Yin and Tomas Pfister},
  title = {{SQL-PaLM: Improved Large Language Model Adaptation for Text-to-SQL}},
  year = {2023},
  eprint = {2306.00739},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2306.00739},
}
Figure