SQL Generation via Machine Reading Comprehension (2020)

Abstract: Text-to-SQL systems offers natural language interfaces to databases, which can automatically generates SQL queries given natural language questions. On the WikiSQL benchmark, state-of- the-art text-to-SQL systems typically take a slot-filling approach by building several specialized models for each type of slot. Despite being effective, such modularized systems are complex and also fall short in jointly learning for different slots. To solve these problems, this paper proposes a novel approach that formulates the task as a question answering problem, where different slots are predicted by a unified machine reading comprehension (MRC) model. For this purpose, we use a BERT-based MRC model, which can also benefit from intermediate training on other MRC datasets. The proposed method can achieve competitive results on WikiSQL, suggesting it being a promising direction for text-to-SQL.

## introduction text-to-sql systems generate sql queries according to given natural language (nl) queries, as shown in example (1), where the headers in the table schema are {player, country, year(s) won, total, to par, finish}. text-to-sql technology is very useful as it can empower humans to naturally interact with relational databases, which serve as foundations for the digital world today. as a subarea of semantic parsing @xcite ), text-to-sql is known to be difficult due to the flexibility in natural language. recently, by the development of deep learning, significant advances have been made in text-to-sql. on the wikisql @xcite ) benchmark for multi-domain, single table text-to-sql task, state-ofthe-art systems @xcite can predict more than 80% of entire sql queries correctly. most of such systems take a slot-filling approach @xcite that builds several (e.g. 6) specialized models, each of which is dedicated to predicting a particular type of slots, such as the column in select, or the filter value in where. for practical applications, however, such methods have two drawbacks: first, it is complex and delicate in architecture to rely on many dedicated modules working together to generate sqls, which poses challenges in (joint) training, deployment and maintenance. second, since most slot types are modeled with no or only limited dependencies on other slots, it is difficult for such models to leverage inter-dependencies of sql slots. to deal with such problems, this paper formulates text-to-sql as a question answering task (section 3). in this formulation, we use a unified bert-based @xcite machine reading comprehension (mrc) model to predict each type of sql slots by answering template-generated questions. then the sql query is synthesized in the way as in slot-filling approaches. for instance, the sql query for the example (1) can be re-constructed by answering questions, some of which are shown in context: query: who is the player from the united states with a total less than 293? header: player, country, year(s) won, total, to par, finish, agg: empty maximum minimum count sum average. ## method task formulation and dataset conversion given a question @xmath0..q l , and a context passage @xmath1...c m , were |q| = l and |c| = m are their token numbers. the task is to find the start token c start and end token c end in the context passage for the given question. some example questions and their context are shown in since there are multiple filters in one sql in wikisql dataset, the mrc method transforms into a multi-turn procedure. in each turn of this procedure, one type of slot will be asked according to results from previous turns. for example in ## conclusion this paper proposes a question answering approach to text-to-sql, where a bert-based mrc model is trained to predict all the slots that are needed for sql generation. our approach enjoys advantages of easier deployment and maintenance in practice, as well as the potentials in leveraging other mrc datasets via the stilts supplementary training. capable of jointly learning slots with a simple, unified model, the proposed method proves to be a promising direction for text-to-sql. as future work, we plan to extend our model to cope with multi-table text-to-sql task, spider.