A Tale of Two Linkings: Dynamically Gating between Schema Linking and Structural Linking for Text-to- SQL Parsing (2020)

Abstract: In Text-to-SQL semantic parsing, selecting the correct entities (tables and columns) for the generated SQL query is both crucial and challenging; the parser is required to connect the natural language (NL) question and the SQL query to the structured knowledge in the database. We formulate two linking processes to address this challenge: schema linking which links explicit NL mentions to the database and structural linking which links the entities in the output SQL with their structural relationships in the database schema. Intuitively, the effectiveness of these two linking processes changes based on the entity being generated, thus we propose to dynamically choose between them using a gating mechanism. Integrating the proposed method with two graph neural network-based semantic parsers together with BERT representations demonstrates substantial gains in parsing accuracy on the challenging Spider dataset. Analyses show that our proposed method helps to enhance the structure of the model output when generating complicated SQL queries and offers more explainable predictions.

## introduction semantic parsing, which aims at mapping natural language (nl) utterances to computer understandable logic forms or programming languages, has been an active research topic in the field of natural language processing (nlp) for decades @xcite . although a variety of logic forms have been studied by researchers, text-to-sql has particularly attracted a large amount of attention due to the desire of natural language interfaces to database (nlidb) @xcite @xcite for both scientific and industrial reasons. recently, there is a growing interest in neural based text-to-sql semantic parsing, thanks to the development of new evaluation paradigms and datasets @xcite @xcite . text-to-sql parsing requires strict structured prediction due to its application scenario where the output sql will be sent to an executor program directly. to enhance the capacity of an auto-regressive model to capture structural information, current state-of-the-art semantic parsers usually adopt a grammar-based decoder @xcite @xcite . rather than directly generating the tokens in a traditional sequence-to-sequence manner, grammar-based decoders produce a sequence of production rules to construct an abstract syntax tree (ast) of the corresponding sql. as the grammar constraints narrows down the search space to only grammatically valid asts, those parsers can usually generate well-formed sql skeletons @xcite . however, it is still difficult for current state-of-the-art models to fill in the skeletons with semantically correct entities, especially when they are required to generalize to unseen db schemas @xcite . to predict the correct entity, the model should have a database (db) schema grounded understanding of the nl question, which means that the model should be able to jointly learn the semantics in the nl question and the structured knowledge in a given database. we formulate two types of entity generation problems, which can be addressed by the following two linking processes respectively. 1 q: for each continent, list its id, name, and how many countries it has? select t1 . contid , t1 . continent , @xcite underline indicates the mention can only be resolved by linking to a cell value or common sense reasoning. schema linking. schema linking @xcite ) is an instance of entity linking @xcite in the context of linking to relational db schema. text-to-sql semantic parsers should learn to recognize an entity mention in the nl question and link it to the corresponding unique entity in the db schema. this task can be challenging due to the diversity and ambiguity nl mentions. however, in practice, the solution is often relatively easy when a particular entity is well realized with similar wording in both the nl question and db schema. as shown in ## approach in this section, we first formulate the text-to-sql semantic parsing task in §2.1. we will then describe the details of our proposed method in §2.2. ## model implementation in this section, we describe how we integrate our proposed method into a grammar decoder and leverage the entity representation from a gnn module. we use the type constrained grammar decoder from @xcite . to predict a t at time step t, the decoder will first obtain the context vector c t from the nl encoder by performing dot-product attention @xcite . then the action embedding is generated by a feed-forward network taking the concatenation of decoder hidden state and context vector as input. a t is used to predict the production rule or estimate the gate values in the entity generation process. we adopt the idea from @xcite to learn a schema relation-aware entity representation h v by a gnn module. 3 the initial embedding of each entity h (0) e is defined as a non-linear transformation of the combination of its type embedding and the average over the word embeddings of its neighbors in the schema graph. in later time steps, the hidden state is updated by a gated recurrent unit @xcite as h (l) @xmath0, x (l) e , where the input x (l) e they consider three edge types, i.e., bidirectional edges between a table and its contained columns ↔, unidirectional edges between a foreign key and a connected primary key ← and its reverse version →. given a fixed gnn recurrence step l, we have the final hidden states of all the entities in the graph as the entity representation to augment our model with pretrained bert embeddings, we follow @xcite and @xcite to feed the concatenation of nl question and the textual descriptions of db entities to bert and use the top layer hidden states of bert as the input embeddings. ## experiments we evaluate the effectiveness of our proposed method by integrating it into two state-of-the-art semantic parsers on the spider dataset and further ablate out some components to understand their contributions. ## conclusion in this paper, we formulated the entity generation process in text-to-sql semantic parsing as two kinds of linking problems, namely schema linking and structural linking. we further proposed a dynamic gating mechanism to explicitly model the decision between these two linking processes. experimental results show the effectiveness of our proposed method and confirm our intuitions. in the future, we would like to apply our proposed method to other semantic parsing tasks, such as general purpose code generation, where structural constraints may be more important.