Seq2SQL :使用强化学习通过自然语言生成SQL
Seq2SQL属于natural language interface (NLI)的领域,方便普通用户接入并查询数据库中的内容,即用户不需要了解SQL语句,只需要通过自然语言,就可查询所需内容。
Seq2SQL借鉴的是Seq2Seq的思想,与Seq2Seq应用于机器翻译与Chatbot类似,Seq2SQL将输入的语句encode后再decode成结构化的SQL语言输出,强化学习是在Seq2SQL中的最后一个模块中应用。同时,这篇论文还推出一个数据集WikiSQL,数据集内有人工标注好的问句及其对应SQL语句。
试验结果显示,Seq2SQL的准确率也不是特别的高,只有60.3%
Seq2SQL结构:
Seq2SQL由三部分组成:

第一部分: Aggregation classifier 这一部分其实是一个分类器,将用户输入的语句分类成是select count/max/min 等统计相关的约束条件
在此处采用的Augmented Pointer Network,Augmented Pointer Network总体而言也是ecoder-to-decoder的结构,
encoder采用的是两层的bi-LSTM, decoder 采用的是两层的unidirectional LSTM,
encoder输出h,ht对应的是第t个词的输出状态
decoder的每一步是,输入y s-1,输出状态gs,接着,decoder为每个位置t生成一个attention的score


在Seq2SQL中,首先为input生成一个表征向量
(agg:aggregation clasifier, inp:input,enc:encoder) 首先为Augmented Pointer Network类似,计算出一个attention的分数,
,



量化后,通过softmax函数 

input的表征向量 

通过一个多层的网络和softmax完成分类任务


第二部分: select column 这一部分是看用户输入的问句命中了哪个column
首先将每个column name 通过LSTM encode

WikiSQL: 

将用户输入encode成与第一部分
类似的


最终通过一个多层的神经元和softmax确定是命中哪一行


第三部分:where clause 确定约束条件,因为最终生成的SQL可能与标注中的不太一样,但是依旧有一样的结果,所以不能像前两部分一样使用交叉熵作为loss训练,因此使用强化训练中reward函数 (g: ground-truth), loss使用梯度

WikiSQL包含一系列与SQL相关的问题集以及SQL table


【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步