Skip to main content
QUICK REVIEW

[论文解读] Type- and Content-Driven Synthesis of SQL Queries from Natural Language

Navid Yaghmazadeh, Yuepeng Wang|arXiv (Cornell University)|Feb 3, 2017
Logic, programming, and type systems参考文献 40被引用 22
一句话总结

该论文提出 Sqlizer,一种与数据库无关的系统,通过三阶段流程从自然语言生成 SQL 查询:语义解析生成查询草图,类型导向合成以置信度评分完成草图,以及自动修复以修正模式不匹配。该方法在三个数据库上的测试用例中实现了 89% 的 top-5 准确率,优于当前最先进的 NLIDB 系统。

ABSTRACT

This paper presents a new technique for automatically synthesizing SQL queries from natural language. Our technique is fully automated, works for any database without requiring additional customization, and does not require users to know the underlying database schema. Our method achieves these goals by combining natural language processing, program synthesis, and automated program repair. Given the user's English description, our technique first uses semantic parsing to generate a query sketch, which is subsequently completed using type-directed program synthesis and assigned a confidence score using database contents. However, since the user's description may not accurately reflect the actual database schema, our approach also performs fault localization and repairs the erroneous part of the sketch. This synthesize-repair loop is repeated until the algorithm infers a query with a sufficiently high confidence score. We have implemented the proposed technique in a tool called Sqlizer and evaluate it on three different databases. Our experiments show that the desired query is ranked within the top 5 candidates in close to 90% of the cases.

研究动机与目标

  • 解决现有自然语言到 SQL 系统存在的局限性,这些系统需要针对特定数据库进行训练或依赖用户指导。
  • 实现在无需用户了解底层模式的情况下,完全自动化、与数据库无关的 SQL 查询合成。
  • 在用户描述与实际数据库模式不匹配的复杂场景中提高准确性。
  • 将语义解析、类型导向合成和程序修复整合为一个稳健的、迭代式的查询合成流水线。

提出的方法

  • 使用语义解析生成查询草图——即从自然语言输入中提取的部分、与模式无关的所需查询结构表示。
  • 应用类型导向程序合成,通过类型安全和数据库内容的引导,枚举并完成草图,填入有效的数据库项(如表、列、谓词)。
  • 利用自然语言描述和数据库中的实际数据值,为每个完成的查询分配置信度评分。
  • 当未找到高置信度完成时,执行故障定位,识别草图中最可能出错的部分。
  • 应用预定义的修复策略数据库,迭代地优化草图并生成新的候选草图。
  • 对每个草图最多重复 n 次合成与修复循环,然后根据置信度评分对所有结果查询进行排序,并返回前 m 个结果。

实验结果

研究问题

  • RQ1一个自然语言到 SQL 的系统是否能在不依赖数据库特定训练或模式知识的情况下实现高准确率?
  • RQ2语义解析、类型导向合成和自动修复的结合在处理因用户误解导致的模式不匹配方面有多有效?
  • RQ3该系统是否能在无需定制化的情况下,在多种数据库上保持高精度?
  • RQ4基于自然语言和数据内容的置信度评分机制如何提升查询选择的性能?

主要发现

  • Sqlizer 在三个不同数据库的 455 个查询上实现了 89% 的 top-5 准确率,表现出强大的泛化能力。
  • 在非交互模式下,该系统显著优于当前最先进的 NLIDB 系统 Nalir,特别是在处理复杂或模糊的用户描述方面。
  • 查询草图的使用使系统无需在特定数据库上进行预先训练,从而实现完全的数据库无关性。
  • 自动修复与故障定位的集成使系统能够纠正初始草图中的结构性错误,当用户的描述未能准确反映数据库模式时。

更好的研究,从现在开始

从阅读论文到最终审阅,大幅缩短您的研究时间。

无需绑定信用卡

本解读由 AI 生成,并经人工编辑审核。