論文:SeaD: End-to-end Text-to-SQL Generation with Schema-aware Denoising
??
NAACL 2022, arXiv:2105.07911
本論文提出 SeaD 模型,使用 schema-aware 的去噪方法來訓練一個 end2end、seq2seq 的 Transformer 模型來實現 Text2SQL。
一、論文速讀
給定一個 question Q Q Q 和一個 schema S S S,我們期望生成相應的 SQL 查詢 Y Y Y。
1.1 model 的輸入輸出
SeaD 的輸入輸出如下圖所示:
在 input 中,將 table headers 的各個 column name 前面加一個 <col n>
表示第幾個 column,然后跟著 column name 和 type,比如對于 week 字段,就是 <col0>week:int
。
在期待的 output 中,SQL 的 column name 使用 “`” 這個 token 圍繞,并將 name 換為分隔符 <col n>
,如上圖所示。
1.2 Transformer with Pointer
該工作使用 Transformer 作為 backbone 來做 seq2seq 任務。
為什么使用 Transformer with Pointer?在 Text2SQL 任務中,大多數的 schema 和 value mentions 可以從 input seq 中抽取出來,所以在 Transformer 架構的最上面加了一個 Hybrid Pointer Generator Network 來生成 token,生成的 token 來自于 target vocabulary V V V 或者 copy from the input text。
target vocabulary V V V 由三個集合組合而成:
- V q V_q Vq? 表示 corpora token vocabulary
- V c V_c Vc? 表示 column token set
- V s V_s Vs? 表示可用的 SQL keywords
Transformer with Pointer 的具體思路可以參考原論文,這里做一個概述:使用 Transformer 中 decoder 生成的 h d e c h_{dec} hdec? 計算出 target vocabulary V V V 中各個 token 的 unnormalized scores s c o r e s v scores_{v} scoresv? 和 input seq 中各個 token 的 unnormalized scores s c o r e s s scores_{s} scoress?,然后將兩個 scores 合并為 s c o r e h y b r i d score_{hybrid} scorehybrid?,最終輸出的概率分布就是 P = s o f t m a x ( s c o r e h y b r i d ) P = softmax(score_{hybrid}) P=softmax(scorehybrid?)。
1.3 Schema-aware Denoising
與 masted LM 和其他去噪任務類似,這里提出了兩個 schema-aware denoising 的訓練方法:erosion 和 shuffle。
1.3.1 Erosion
參考上圖,對 table schema S S S 中的 column name 做 erosion 操作,主要是做重排、增加和刪除操作來引入噪聲,同時 <col n>
分隔符保持不變。
如果一個 column 被刪除但是生成的 SQL 需要使用它,則生成 SQL 中使用 <unk>
來替代,這能讓 model 學會當 schema 信息不足時拋出 unknown exception。
1.3.2 Shuffle
參考上圖,將 source query Q Q Q 中的提及的實體(question 和 SQL)重新排序,而 schema seq S S S 保持不變。這個 denoisiong objective 訓練模型重構實體順序正確的查詢序列 Q Q Q。
二、總結
實驗在 test 結果上達到了 93 的準確率,但沒有公開 code。但本文提出的思路還是值得學習的。