TL;DR
CodeS is a new family of open-source language models (ranging from 1B to 15B parameters) specifically optimized for the Text-to-SQL task. By using incremental pre-training on a curated SQL-centric corpus and novel prompt construction techniques, CodeS achieves state-of-the-art (SOTA) performance on major benchmarks like Spider and BIRD, often outperforming much larger closed-source models like GPT-4 while being significantly faster and more private.
What Problem Does This Paper Address?
The current "gold standard" for translating natural language questions into SQL (Text-to-SQL) relies heavily on massive, closed-source models like GPT-4. While powerful, these models present three major hurdles for researchers and engineers:
- Privacy: Sending sensitive database schemas and queries to a third-party API is a non-starter for many industries (e.g., finance, healthcare).
- Cost and Latency: High-parameter models are expensive to run and often take nearly a minute to generate a single complex query.
- Domain Adaptation: General-purpose LLMs often struggle with "schema linking"—the ability to correctly map a user's vague question to specific, often cryptically named, database columns and tables.
Small open-source models typically lack the reasoning depth to handle complex joins or large-scale databases. CodeS aims to bridge this gap by proving that a specialized, smaller model can match or beat the giants.
Methods
The authors built CodeS on top of StarCoder, using a three-pronged strategy:
- Incremental Pre-training: Instead of simple fine-tuning, they performed incremental pre-training on a massive 21.5GB "SQL-centric" corpus. This included 11GB of raw SQL, 6GB of natural-language-to-code pairs, and 4.5GB of high-quality dialogue data. This "soaked" the model in SQL logic before it ever saw a specific benchmark.
- Database Prompt Construction: To handle real-world databases with hundreds of columns (which would exceed a model's context window), they implemented a Schema Filter (a neural classifier to pick relevant tables) and a Value Retriever. The retriever uses a "coarse-to-fine" approach: first using BM25 to find potential cell values, then refining them with a Longest Common Substring (LCS) algorithm.
- Bi-directional Data Augmentation: To help the model adapt to new domains with zero or few labels, they used GPT-3.5 to generate new (Question, SQL) pairs in two directions: turning existing SQL templates into natural questions and evolving a few seed user questions into a broader set of synthetic queries.
Datasets
The researchers evaluated CodeS across an impressive array of benchmarks:
- Spider: The standard cross-domain Text-to-SQL benchmark.
- BIRD: A newer, much more challenging benchmark featuring large-scale databases (33.4GB) and "dirty" data.
- Robustness Benchmarks: Spider-DK, Spider-Syn, Spider-Realistic, and Dr.Spider, which test how models handle synonyms and perturbations.
- New Real-World Datasets: The authors introduced Bank-Financials and Aminer-Simplified to test performance in specialized professional domains.
Key Insights and Ideas
- Specialization Trumps Scale: One of the most striking findings is that SFT CodeS-7B (a 7-billion parameter model) outperformed GPT-4-based methods on the Spider development set. This suggests that for specific tasks like SQL generation, a well-trained "small" model is more efficient than a "jack-of-all-trades" giant.
- The "Coarse-to-Fine" Value Retrieval: In the BIRD benchmark, databases are massive. The authors found that simply searching for values using LCS was too slow, but using BM25 alone was too imprecise. Combining them allowed CodeS to find the exact string (e.g., a specific branch name like "Jesenik") needed for a
WHEREclause without melting the CPU. - Schema Filtering is Non-Negotiable: For real-world applications where a database might have 60+ columns per table, filtering the prompt down to only the relevant schema items is essential for both accuracy and staying within the model's token limit.
Key Results
- SOTA Performance: CodeS-15B reached the top of the BIRD official leaderboard (at the time of writing), achieving 52.15% Execution Accuracy (EX) on the test set, a significant jump over previous baselines.
- Efficiency: While a GPT-4-based pipeline (like DIN-SQL) takes roughly 60 seconds per query, CodeS-7B generates the same query in about 1.1 seconds.
- Robustness: CodeS showed superior resilience to "noise"—it maintained higher accuracy than competitors when questions were rephrased with synonyms or when the database schema was slightly perturbed.
Limitations and Future Work
- Context Window: Despite optimizations, the models are still limited by context length (8k for smaller versions, 6k for 15B). Extremely complex schemas might still face truncation issues.
- Dependency on GPT-3.5 for Augmentation: While the final CodeS model is open-source, the training process still relied on GPT-3.5 to generate and refine synthetic data. Future work could explore using fully open-source pipelines for the data augmentation stage.
- Multi-turn Interaction: The current paper focuses primarily on single-turn Text-to-SQL. Expanding this to multi-turn "chat-with-your-data" scenarios is a natural next step.
Summary updated