[论文解读] CodeS: Towards Building Open-source Language Models for Text-to-SQL
CodeS 提供开源的、专注于文本到 SQL 的大型语言模型(1B–15B),通过对 SQL 为中心的数据进行增量预训练构建,配备模式感知的提示和双向领域自适应,在多个基准测试上达到 SOTA。
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.
研究动机与目标
- 出于隐私、成本和透明度等考虑,推动文本到 SQL 的开源替代方案以替代封闭的大型语言模型。
- 开发 CodeS 模型(1B–15B),通过对 SQL 为中心的语料进行增量预训练,定制用于 SQL 生成。
- 通过数据库提示和双向数据增强来改进模式链接和领域自适应。
- 在多样的文本到 SQL 基准和真实世界领域中展示鲁棒性和准确性提升。
提出的方法
- 对 curated SQL 为中心的语料进行增量预训练,StarCoder 的总量为 21.5GB(11GB 与 SQL 相关,6GB 与 NL-to-code 相关,4.5GB 与 NL 相关)。
- 开源 CodeS 模型参数量范围为 1B 到 15B(CodeS-1B/3B/7B/15B)。
- 数据库提示构建采用模式筛选和数值检索器,以生成紧凑且信息丰富的提示,包含元数据(类型、注释、代表值、键)。
- 用于新领域自适应的双向数据增强,将真实问题/ SQL 注解与 GPT-3.5 生成的配对以及基于模板的 SQL-to-question/ question-to-SQL 合成相结合。
- 使用场景包括当数据充足时的有监督微调,以及数据有限时利用演示的检索器进行少样本/上下文学习。
- 复杂性考量将离线(增量预训练、领域自适应)与在线(提示构建)阶段区分开来;基于 BM25 的粗到细值检索加速在线提示。
实验结果
研究问题
- RQ1一个使用 SQL 为中心数据训练的开源 LLM 能否在文本到 SQL 任务上达到与大型闭源 LLM 相当的表现?
- RQ2如何在人为的大型、异质或模糊的模式下设计模式链接和提示?
- RQ3在标注数据有限的情况下,哪些策略能实现文本到 SQL 模型对新领域的快速自适应?
- RQ4双向数据增强是否能提高领域迁移与在具有挑战性的基准上的鲁棒性?
主要发现
- CodeS 在微调后在具有挑战性的文本到 SQL 基准上实现了新的 SOTA 精度与鲁棒性。
- CodeS 展示了 1B–15B 规模的开源 SQL 生成性能显著优于现有的 SOTA 大模型;规模更小。
- 一种综合性的数据库提示策略(模式筛选+数值检索)提升了模式链接和查询准确性。
- 双向数据增强使在标注数据有限的情况下快速适应新领域成为可能,结合真实查询与模板化的 SQL-to-question 及 question-to-SQL 生成。
- 评估覆盖 Spider 的变体(DK、Syn、Realistic、Dr.Spider)、BIRD,以及金融和学术领域的两个真实世界数据集。
阅读本论文
在 Nubint 阅读器中打开原文,边读边就任意段落提问。
在 Nubint 中阅读本论文本解读由 AI 根据论文原文生成,引用前请核对原文。