Seq2SQL: Generating Structured Queries from Natural Language using Reinforcement Learning
Victor Zhong, Caiming Xiong, Richard Socher Salesforce Research Palo Alto, CA
Abstract
Relational databases store a significant amount of the world’s data. However, accessing this data currently requires users to understand a query language such as SQL. We propose Seq2SQL, a deep neural network for translating natural language questions to corresponding SQL queries. Our model uses rewards from in-the-loop query execution over the database to learn a policy to generate the query, which contains unordered parts that are less suitable for optimization via cross entropy loss. Moreover, Seq2SQL leverages the structure of SQL to prune the space of generated queries and significantly simplify the generation problem. In addition to the model, we release WikiSQL, a dataset of 80654 hand-annotated examples of questions and SQL queries distributed across 24241 tables from Wikipedia that is an order of magnitude larger than comparable datasets. By applying policy-based reinforcement learning with a query execution environment to WikiSQL, Seq2SQL outperforms a state-of-the-art semantic parser, improving execution accuracy from 35.9% to 59.4% and logical form accuracy from 23.4% to 48.3%.
中文速览
把自然语言问题自动转换成SQL查询,一直受制于缺乏大规模标注数据和模型难以处理SQL语义结构两大瓶颈。研究者提出了Seq2SQL这一深度神经网络,将SQL查询拆解为聚合操作、SELECT列和WHERE子句三个结构化子任务分别预测,其中对顺序无关的WHERE条件采用强化学习(policy-based reinforcement learning)通过实际执行查询获得奖励信号来训练,从而避免了交叉熵损失错误惩罚语义等价但顺序不同的写法。与此同时,他们发布了WikiSQL数据集,包含来自24241张维基百科表格的80654条人工标注问答对,规模比同类数据集大一个数量级。实验结果显示,Seq2SQL在执行准确率上从此前最优的35.9%提升至59.4%,证明了结构化建模与强化学习结合的有效性,也为后续自然语言接口研究提供了重要的基准资源。
原文 arXiv:1709.00103;中英对照 + 大白话阅读 https://aha.fim.ai/paper/1709.00103v7