1. Representing Schema Structure with Graph Neural Networks for Text-to-SQL Parsing
  2. Global Reasoning over Database Structures for Text-to-SQL Parsing
  3. Grammar-based Neural Text-to-SQL Generation

What are terminal and nonterminal symbols?

Representing Schema Structure with Graph Neural Networks for Text-to-SQL Parsing

https://github.com/benbogin/spider-schema-gnn

In this paper, we present an encoder-decoder semantic parser, where the structure of the DB schema is encoded with
a graph neural network, and this representation is later used at both encoding and decoding time.

定义问题:

  • 给定:,其中为question、为SQL query、为schema
  • 目标:map unseen question-schema pair (x, S)
  • 对于schema S包含:
    1. set of DB tables:
    2. set of columns: for each
    3. set of foreign key pair:
    4. 统称所有的schema tables & columns 为 schema items,记作:

其他相关笔记:

A Neural Semantic Parser for SQL

定义词语和schema item $v$的相似度打分 ($v$ has type $\tau$)

则有:

$p_{link}(v|x_i)=\frac{exp(s_{link}(v, x_i))}{\sum_{v' \in \mathcal{V}_{\tau} \cup \{\emptyset \}exp(s_{link}(v', x_i)))}}$

其中,为所有的schema items

Encoder

包含两个输入:

  1. word embedding
  2. ,其中是对每个schema item $v$的邻居和type学出的embedding

这样,通过schema items增强了每个词语$x_i$的语义

Decoder

这里使用了一个grammar-based LSTM decoder with attention

Rule分为:

  • schema-independent and generate non-terminals or SQL keywords
  • schema-specific and generate schema items

对于,每个decoding step $j$,将有:,若Rule:

  • schema-independent: $g_j$为一个学到的global embedding
  • schema-specific: $g_j$ 是一个schema item $v$的type的学到的embedding

完整的计算过程如下:

  • $a_j=h_i^{ \intercal}o_j$
  • $c_j=\sum_i{a_j h_j}$
  • $s_j^{glob}=FF([o_j;c_j])$
  • $p_j=softmax([s_j^{glob};s_j^{loc}])$

Modeling Schemas with GNNs

image

模型包含以下内容:

  1. schema转换为一个graph
  2. 此graph根据输入的question进行了soft修剪
  3. GNN根据全局schema对节点生成表示
  4. encoder、decoder均用了schema representation

以下进行详细介绍

Schema-to-graph

为了将schema S转为graph,定义以下内容:

  • graph node(schema items $\mathcal{V}$)
  • edge:
    • 对于tabel 中的column ,定义:set 图中绿边
    • 对于foreign-primary key column pair,定义:
      • 图中虚线

Question-conditioned relevance(问题-条件的相关性)

对schema item $v$定义相关性打分:

$$\rho_v=max_i p_{link}(v|x_i)$$

图中,相关的schema items为深橘黄色,无关的item为浅橘黄色

Neural graph representation

对于每个节点,得到:,然后通过$L$ step的GNN,在每步中,

$$a_v^{(l)}=\sum_{type \in \{\rightarrow, \leftrightarrow\}} \sum_{(u,v) \in \varepsilon_{type}}W_{type}h^{l-1}_u +b_{type}$$
$$h_v^{(l)}=GRU(h_v^{(l-1)}, a_v^{(l)})$$

在$L$ step后,得到:

Encoder

$$L_i^{\rho}=\sum_{\mathcal{T}} \sum_{v \in \mathcal{V}_{\mathcal{T}}} \rho_v p_{link}(v|x_i)$$

然后将与encoder输出的$h_i$进行concat

Decoder

定义矩阵

Global Reasoning over Database Structures for Text-to-SQL Parsing

这篇是上面一篇的改进工作

https://github.com/benbogin/spider-schema-gnn-global

In this paper, we propose a semantic parser that reasons over the DB structure and question to make a global decision about which DB constants should be used in a query.

  1. 本文提供了一个GNN来获取DB schema的表示,从而选择可能在query中出现的db 常量(db constants)
  2. 训练自回归模型的top-k个查询,然后重排序

Schema-augmented Semantic Parser

Problem Setup部分与上文完全一样,用进行表示。

Base Model

具有基于语法的解码的标准自上而下语义解析器

输入的问题()通过BiLSTM进行encoding,获取隐层表示$e_i$来表示$x_i$的信息。然后通过另一个LSTM使用SQL语法进行decoding获取输出$y$

当前一步解码无符号的table和column时,解析器开始解码DB常量。为了选择DB常量,做了下面的操作:

  1. 在question上面计算attention:
  2. 对于DB常量 $v$计算打分:,这里可以根据word embedding或者其他特征得到,例如两个输入的编辑距离or重复文本

DB schema encoding

根据上一篇论文,通过将DB schema转为graph,对每个DB常量学得一个表示:$h_v$,然后通过GCN对每个节点的$h_v$进行端到端的学习。

为了将GCN的能力集中在节点上,将计算每个节点的关联概率:$\rho_v$,并将问题当作条件控制“门”进行输入GCN。(这句没理解)

  1. 对于每个database constant,GCN的输入为:
  2. GCN循环$L$步
  3. final:

上面的$\rho_v$会在下面详细介绍

Global Reasoning over DB Structures

image

  1. 使用Gating GCN为每个DB constant预测相关分数(relevance score)
  2. 使用encoder GCN对每个DB constant计算表示,然后预测K个候选query
  3. re-ranking GCN基于选择的DB constant,对这些候选依次打分

图里虚线和箭头表示因为decoder输出SQL query,因此没有梯度从re-ranking GCN传递到decoder

Global gating

输入部分与上面提到的graph完全一样,但是多了新的节点:$v_{global}$

定义在节点$v$的GCN输入为:,其中为question tokens的表示的weight average

这样,通过最后一步的graph表示计算得到一个相关性概率:,这个概率代替了$\rho_v$作为encoder GCN的输入

由于已知question对应的query $y$,因此可以得到对应的DB constants $\mathcal{u}_y$

故,可以定义relevance loss,这样gating GCN可以根据relevance loss和decoding loss训练。

Discriminative re-ranking

对于每个候选计算re-ranker打分, 为候选query

计算logit: ,其中:

  • $\omega$是学来的参数
  • 是set $\mathcal{u}$的表示
  • $e^{align}$是question和db constants之间的对齐表示

re-ranker试图对正确的query $y$最小化re-ranker loss

对于re-ranking GCN来说,输入仅为:

  • 包含被选择的$u_{\hat{y}}$的子图
  • 全局节点$v_{global}$

因此输入可以用:进行表示,经过$L$ step后,得到:,至此,得到:

对于的每个节点定义表示:

  • $r_v$ otherwise

然后计算:,然后链接:

Grammar-based Neural Text-to-SQL Generation

TODO