arXiv:2502.10739cs.CL2025-02被引 13

用开源模型实现高效精准的自然语言转SQL,效果超闭源模型。

BASE-SQL: A powerful open source Text-To-SQL baseline approach

  • 基于微调开源模型的四阶段流水线,分步生成并优化SQL。
  • 在Spider测试集上达88.9%准确率,超越多个闭源模型。
  • 仅需平均5次调用大模型,易复现且适合实际部署。

自然语言转SQL技术在数据库查询中应用广泛,当前主流方法分为基于上下文学习(ICL)和监督微调(SFT)。ICL方法虽性能优越,但受限于数据隐私、效率与成本。SFT方法更具实用性,但现有开源模型微调方案缺乏高效易用的基线。本文提出BASE-SQL,一个基于开源模型微调的流水线方法,包含模式链接、候选SQL生成、SQL修订和合并修订四个模块。实验表明,使用Qwen2.5-Coder-32B-Instruct模型,BASE-SQL在BIRD开发集上达到67.47%准确率,在Spider测试集上达88.9%,显著优于其他开源模型方法,甚至超过部分GPT-4o闭源模型。该方法实现简单,平均仅需5次大模型调用即可生成一条SQL,具有高效率与可扩展性。代码将开源至https://github.com/CycloneBoy/base_sql。

原文摘要 · Abstract (English)

The conversion of natural language into SQL language for querying databases (Text-to-SQL) has broad application prospects and has attracted widespread attention. At present, the mainstream Text-to-SQL methods are mainly divided into in-context learning (ICL) based methods and supervised fine-tuning (SFT) based methods. ICL-based methods can achieve relatively good results thanks to the use of the most advanced closed-source models. However, in real-world application scenarios, factors such as data privacy, SQL generation efficiency and cost need to be considered. SFT-based methods have certain advantages. At present, methods based on fine-tuning of open source models lack easy-to-implement and effective (cost-effective) baseline methods. We propose a pipeline-based method using open source model fine-tuning, referred to as BASE-SQL, which includes four components: Schema Linking, Candidate SQL Generate, SQL Revision and SQL Merge Revision. Experimental results show that BASE-SQL uses the open source model Qwen2.5-Coder-32B-Instruct, and achieves an accuracy of 67.47% on the BIRD development set and 88.9% on the Spider test set, which is significantly better than other methods using open source models, and even exceeds several methods using the GPT-4o closed-source model. At the same time, BASE-SQL is easy to implement and highly efficient (on average, only five calls to the large language model are required to generate SQL once). The code will be open sourced at https://github.com/CycloneBoy/base_sql.

Text-to-SQL开源模型SQL生成大模型应用

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。