Skip to main content
QUICK REVIEW

[Paper Review] CodeS: Towards Building Open-source Language Models for Text-to-SQL

Haoyang Li, Jing Zhang|arXiv (Cornell University)|Feb 26, 2024
Advanced Database Systems and QueriesComputer Science5 citations
TL;DR

CodeS presents open-source, text-to-SQL specialized LLMs (1B–15B) built via incremental pre-training on SQL-centric data, with schema-aware prompts and bi-directional domain adaptation, achieving SOTA on multiple benchmarks.

ABSTRACT

Language models have shown promising performance on the task of translating natural language questions into SQL queries (Text-to-SQL). However, most of the state-of-the-art (SOTA) approaches rely on powerful yet closed-source large language models (LLMs), such as ChatGPT and GPT-4, which may have the limitations of unclear model architectures, data privacy risks, and expensive inference overheads. To address the limitations, we introduce CodeS, a series of pre-trained language models with parameters ranging from 1B to 15B, specifically designed for the text-to-SQL task. CodeS is a fully open-source language model, which achieves superior accuracy with much smaller parameter sizes. This paper studies the research challenges in building CodeS. To enhance the SQL generation abilities of CodeS, we adopt an incremental pre-training approach using a specifically curated SQL-centric corpus. Based on this, we address the challenges of schema linking and rapid domain adaptation through strategic prompt construction and a bi-directional data augmentation technique. We conduct comprehensive evaluations on multiple datasets, including the widely used Spider benchmark, the newly released BIRD benchmark, robustness-diagnostic benchmarks such as Spider-DK, Spider-Syn, Spider-Realistic, and Dr.Spider, as well as two real-world datasets created for financial and academic applications. The experimental results show that our CodeS achieves new SOTA accuracy and robustness on nearly all challenging text-to-SQL benchmarks.

Motivation & Objective

  • Motivate open-source alternatives to closed LLMs for text-to-SQL due to privacy, cost, and transparency concerns.
  • Develop CodeS models (1B–15B) tailored for SQL generation through incremental pre-training on SQL-centric corpora.
  • Improve schema linking and domain adaptation via database prompts and bi-directional data augmentation.
  • Demonstrate robustness and accuracy gains on diverse text-to-SQL benchmarks and real-world domains.

Proposed method

  • Incremental pre-training of StarCoder on a curated SQL-centric corpus totaling 21.5GB (11GB SQL-related, 6GB NL-to-code, 4.5GB NL-related).
  • Open-source CodeS models range from 1B to 15B parameters (CodeS-1B/3B/7B/15B).
  • Database prompt construction uses a schema filter and a value retriever to create compact, information-rich prompts with metadata (types, comments, representative values, keys).
  • Bi-directional data augmentation for new-domain adaptation combining real-question/SQL annotations with GPT-3.5 generated pairs and template-based SQL-to-question/question-to-SQL synthesis.
  • Usage modes include supervised fine-tuning when data is abundant and few-shot/in-context learning using a demonstrated retriever when data is limited.
  • Complexity considerations separate offline (incremental pre-training, domain adaptation) and online (prompt construction) phases; BM25-based coarse-to-fine value retrieval accelerates online prompting.

Experimental results

Research questions

  • RQ1Can an open-source LLM trained with SQL-centric data achieve competitive text-to-SQL performance compared with large closed LLMs?
  • RQ2How can schema linking and prompt design be engineered to handle large, diverse, or ambiguous schemas?
  • RQ3What strategies enable rapid adaptation of text-to-SQL models to new domains with limited annotated data?
  • RQ4Does bi-directional data augmentation improve domain transfer and robustness on challenging benchmarks?

Key findings

  • CodeS achieves new SOTA accuracy and robustness on challenging text-to-SQL benchmarks after fine-tuning.
  • CodeS demonstrates superior open-source SQL generation performance with models sized 1B–15B, substantially smaller than existing SOTA LLMs.
  • A comprehensive database prompt strategy (schema filter plus value retriever) improves schema linking and query accuracy.
  • Bi-directional data augmentation enables rapid adaptation to new domains with limited annotation, using real queries plus templated SQL-to-question and question-to-SQL generation.
  • Evaluations cover Spider variants (DK, Syn, Realistic, Dr.Spider), BIRD, and two real-world datasets in finance and academia.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.