用Python代码当桥梁,让自然语言更准生成SQL。
Pi-SQL: Enhancing Text-to-SQL with Fine-Grained Guidance from Pivot Programming Languages
- 通过生成带注释的Python代码,提供细粒度执行步骤指导。
- 最终SQL准确率比最佳基线提升3.20,执行效率评分高出4.55。
- 适合想提升文本转SQL准确率的研究者和开发者。
文本转SQL任务将自然语言查询转化为可执行的SQL程序,使非专业人士也能操作复杂数据库。现有基于提示的方法依赖精细的文本引导和示例,但受限于自然语言与低资源SQL程序之间的巨大语义鸿沟,准确率难以提升。本文提出Pi-SQL,引入高资源的Python程序作为中间桥梁,连接自然语言查询与SQL程序。具体而言,Pi-SQL首先生成带有代码块或注释的Python程序,以细粒度步骤提供指导;随后根据该Python程序生成对应SQL。最终生成的SQL在查询结果上匹配参考Python程序,并通过多种策略候选选择,实现更高的执行速度。在奖励驱动的有效性评分上,最高优于最佳基线4.55分。大量实验表明,该方法可使最优基线的执行准确率提升最高达3.20分。
原文摘要 · Abstract (English)
Text-to-SQL transforms the user queries from natural language to executable SQL programs, enabling non-experts to interact with complex databases. Existing prompt-based methods craft meticulous text guidelines and examples to facilitate SQL generation, but their accuracy is hindered by the large semantic gap between the texts and the low-resource SQL programs. In this work, we propose Pi-SQL, which incorporates the high-resource Python program as a pivot to bridge between the natural language query and SQL program. In particular, Pi-SQL first generates Python programs that provide fine-grained step-by-step guidelines in their code blocks or comments, and then produces an SQL program following the guidance of each Python program. The final SQL program matches the reference Python program's query results and, through selection from candidates generated by different strategies, achieves superior execution speed, with a reward-based valid efficiency score up to 4.55 higher than the best-performing baseline. Extensive experiments demonstrate the effectiveness of Pi-SQL, which improves the execution accuracy of the best-performing baseline by up to 3.20.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。