Recent neural text-to-SQL models can effectively translate natural language questions to corresponding SQL queries on unseen databases. Working mostly on the Spider dataset, researchers have proposed increasingly sophisticated solutions to the problem. Contrary to this trend, in this paper we focus on simplifications. We begin by building DuoRAT, a re-implementation of the state-of-the-art RAT-SQL model that unlike RAT-SQL is using only relation-aware or vanilla transformers as the building blocks. We perform several ablation experiments using DuoRAT as the baseline model. Our experiments confirm the usefulness of some techniques and point out the redundancy of others, including structural SQL features and features that link the question with the schema 1 . Language user interfaces to databases allow nonspecialists to retrieve and process information that might otherwise not be easily available to them. Much of the recent research in this area has focused on neural models that can generalize to new relational databases without any human intervention. Given a relational database schema (and often also content), such models translate the user's question directly into an SQL query (Zhong et al., 2017; Yu et al., 2018a; Bogin et al., 2019). Such cross-database text-to-SQL research was spurred by the introduction of large datasets such as WikiSQL (Zhong et al., 2017) and Spider (Yu et al., 2018b) that feature utterance-query pairs for hundreds or even thousands of databases. State-of-the-art text-to-SQL models employ many sophisticated techniques. These include, but are not limited to, grammar-constrained models  Equal contribution, order was determined by a quantum random number draw. and recurrent neural networks with parent feeding (Yin and Neubig, 2018), intermediate meaning representations (Guo et al., 2019; Suhr et al., 2020), relation-aware attention (Wang et al., 2020), schema linking and table joining heuristics (Guo et al., 2019), slot filling (Choi et al., 2020) and re-ranking (Kelkar et al., 2020) models. The high complexity of these models raises the barrier of entry and can slow down text-to-SQL research. In this work, we attempt to distill the essence of high-performing text-to-SQL systems. We start with a transformer-only reimplementation of the state-of-the-art RAT-SQL model (Wang et al., 2020). Importantly, our resulting DuoRAT model trains three times faster than RAT-SQL. We then systematically study how DuoRAT can be simplified without losing performance. Our ablation study confirms the usefulness of many but not all techniques employed in RAT-SQL. For example, we show that the benefits of explicit matching of question spans with the column or table names ( name-based schema linking , NBSL) become marginal when a pretrained transformer (De-vlin et al., 2018) is used to jointly encode the question and the schema. By contrast, we confirm the benefit of using a grammar to constrain the inference to only produce well-formed queries. These and other findings of our work bring much-needed insight of what enables higher performance in mod-ern text-to-SQL models. Our base model, DuoRAT, is a reimplementation of RAT-SQL (Wang et al., 2020). It is an encoder-decoder model with attention and a pointer-network copy mechanism, Fig. 1. Contrary to RAT-SQL, both the encoder and the decoder are relation-aware transformers (Shaw et al., 2018). The input is modelled as a labelled directed graph, where the nodes are the input tokens and the edges are the so-called relations , see below. Relation-Aware Attention Compared to vanilla self-attention, relation-aware self-attention takes two additional tensor inputs, key relations r ( K ) ij and value relations r ( V ) ij , that amplify or diminish contributions in the scaled dot-product attention for each of the H attention heads: e ( h ) ij = x i W ( h ) Q (cid:16) x j W ( h ) K + r ( K ) ij (cid:17) (cid:124) (cid:112) d z / H (1)  ( h ) ij = exp e ( h ) ij  nk = 1 exp e ( h ) ik (2) z ( h ) i = n  j = 1  ( h ) ij (cid:16) x j W ( h ) V + r ( V ) ij (cid:17) , (3) where x i  R d x is the i -th element of the input sequence,  ( h ) ij is the attention weight coefficient for the h -th head, and z ( h ) i  R d z / H is the i -th output element. The indices i and j run from 1 to n , where n is the length of the sequence. W ( h ) Q , W ( h ) K , and W ( h ) V  R d x  d z / H are trainable weight matrices. r ( K ) ij  R d z / H and r ( V ) ij  R d z / H represent a directed labelled edge pointing from the i -th input x i to the j -th input x j . Following Shaw et al. (2018), we set r ( K ) ij = r ( V ) ij = r ij . The relations r ij are shared across all layers. Let R be the total number of relational edge labels. If the relation s  { 1 ,..., R } exists between the i -th and j -th input, then we assign the s -th learned embedding r ( s ) ij to r ij . Otherwise, we use padding. Encoder The DuoRAT encoder is divided into two stages, a pretrained relation-unaware transformer stage followed by a relation-aware transformer stage that is trained from scratch. The first stage is initialized with BERT weights (Devlin et al., 2018) and is fed embeddings of the question tokens, the table name tokens, the column name tokens, and one token for each column data type. We add [CLS] tokens between segments, cf. Fig. 1 for the input layout. The second stage has two inputs: an input sequence and the input relations corresponding to graph nodes and labelled edges, respectively. The input sequence is comprised of the BERT outputs for all question token positions and the [CLS] token position outputs for each table and each column. We use relational edge labels similar to those introduced by RAT-SQL. The labels are divided into three groups; (i) schema-linking relations, (ii) table-column relations, and (iii) foreign-key relations. (i) Schema-linking relations provide explicit alignment between the question and the schema. We distinguish between name-based schema linking (NBSL) and content-based schema linking (CBSL), where the former uses the names of tables and columns only and the latter uses the database content. An example for NBSL is when the question references a table by name, like singer in Fig. 1. CBSL identifies when the question references a value in a database column, e.g. the word France in Fig. 1. We use a common schema-linking heuristic where question n-grams are compared at the character level with names of tables and columns for NBSL and with the contents of column cells for CBSL. (ii) The table-column relations describe which columns belong to which tables, and which columns occur in the same table. Finally, (iii) the foreign-key relations indicate the foreign key constraints between columns. See Appendix A for a complete list of the encoder relations. (Yin and Neubig, 2018) to relation-aware transformers. Like in the original framework, the decoder is restricted to generate only those sequences of grammar actions that encode a valid SQL abstract syntax tree (AST), see Appendix B. We consider two output grammars, one for complete SQL and another for SQL with underspecified FROM clause (SQLUF ) (Suhr et al., 2020). In a SQLUF query, the FROM clause is replaced by the UF clause that contains only the tables that were not mentioned in other clauses of the original SQL query. After decoding a SQLUF query, we recover the FROM clause by adding tables from other clauses and joining them using the foreign-key relations. RAT-SQL and the TRANX framework use a custom parent-feeding LSTM decoder where the LSTM is fed also its own state from a previous step at which the constructor of the current action's parent AST node was generated. By contrast, in DuoRAT's relation-aware transformer decoder, we experiment with relations that are derived from the structure of the SQL program code, see Appendix A for a list. The relations can bias the transformer decoder towards attending AST parent or sibling nodes, allowing for the model to get a sense of the AST's structure. However, it is unclear whether or not this is necessary in a model with self-attention. The decoder is coupled to the encoder via a relation-aware memory attention mechanism. Here we use relations to indicate which tokens from the input were copied to the output, that is, either question tokens, tables, or columns, depending on the type of the literal that was produced. For most of our experiments we use the Spider dataset (Yu et al., 2018b) and evaluate the predicted SQL with the exact-match (EM) accuracy from the official Spider evaluation script. The Spider training set contains 8,659 questions for 146 databases. The Spider development set contains 1,034 questions for 20 databases. We exclude the baseball1 questions from the training data because the schema of this database is too large. To compare DuoRAT to the models in the literature we evaluate it on the original development set as released on January 8, 2019. In all other experiments we use the corrected development set that was released on June 7, 2020. We also test our Spider-trained models on several System EM (dev.) RYANSQL (Choi et al., 2020) 70 . earlier single-database text-to-SQL datasets, see Section 3.4 for more details on that and Appendix C for details on the training procedure. Table 1 compares DuoRAT's performance on the Spider development set to that of other state-of-the-art models 2 . DuoRAT performs similarly to its close relative RAT-SQL and outperforms other recently proposed models. Importantly, DuoRAT training takes roughly two days compared to six days for RAT-SQL. We associate the difference in speed with replacing RAT-SQL's LSTM-with-parent-feeding decoder with a transformer. Schema Linking Prior work (Wang et al., 2020; Guo et al., 2019) attributes a high value to schema linking, that is, to the engineering of features that ground the user utterance in the database domain. However, this insight rests entirely on experiments without BERT. We find that, for our BERT-based DuoRAT model, name-based schema linking (NBSL) can be disabled with a negligible loss in performance (see Table 2) while content-based schema linking (CBSL) can not. The result suggests that a BERT encoder fine-tunes to perform computation that makes heuristic NBSL redundant. To gain further understanding of whether or how BERT does this, we conduct an experiment in which the inputs to BERT are divided into two logical segments: the question and the schema. We shape the attention mask such that the question segment attends to the schema or the schema attends to the question, or both, or neither. The results are shown in Table 2. We observe that, for the best performance, BERT should 2 Results taken from the Spider leaderboard at https:// yale-lily.github.io/spider on October 19, 2020. be jointly embedding the question and the schema. We can neither embed the question separately from the schema nor the schema separately from the question without substantial performance losses. Interestingly, once we cut all the attention connections between the question and the schema, explicit NBSL becomes essential. This confirms our hypothesis that joint BERT-based encoding of the question and the schema is the cause of the low importance of NBSL in our model. Schema Structure Representation Various ways of encoding which columns belong to which table have been explored: Suhr et al. (2020) orders the schema elements such that each table name is followed by the names of the columns of that table, RAT-SQL (Wang et al., 2020) represents schema structure as table-column relations in the RAT encoder. Our experiments show that encoding the schema structure via encoder relations gives the best performance (first row of Table 4), and encoding it in the order of its elements (third row) is better than not encoding it at all (second row). Additional results can be found in Appendix D. 3.3 Decoder Ablations Decoder Relations And Grammar-Based Constraining Table 3 shows results of ablation stud-Model Variant EM (dev.) [column][table] + relations 69 . ies in which (i) different kinds of decoder relations were removed, in particular those that provide program structure information, and (ii) grammar-based constraining was deactivated during training and/or inference. The experiments provide the following insights: (i) A vanilla transformer decoder can be used without loss of performance. The relations that provide information about the AST and about which literals were copied from the input are not useful. We speculate that AST information can be more useful in deeply nested SQL expressions of which Spider contains only few. (ii) By contrast, grammar constraining at inference leads to significant performance improvements. Notably, training tends to be less stable when not using grammar constraints. The usefulness of grammar constraining can be explained by the fact that it reduces the output space and makes the decoder more data-efficient. Output Format In this section, we examine the performance on the Spider dataset when outputting complete SQL and when outputting simplified SQL with underspecified FROM clause, SQLUF . The results are reported in Table 6. Our first insight is that DuoRAT performance with and without SQLUF is almost the same. Our second insight is that when the encoder does not have access to information about the foreign keys, SQLUF brings a significant improvement. The best result is still achieved with a model that uses the foreign-key input relations. A known issue of the Spider dataset is that the question wordings are unnaturally close to the respective queries (Suhr et al., 2020). To complement our studies on Spider, we perform additional experiments on single-database text-to-SQL datasets that are devoid of this issue. Suhr et al. (2020) propose a demanding cross-domain generalization evaluation whereby models are trained on Spider and Dataset DuoRAT + SQLUF w/o CBSL w/o SQLUF GeoQuery 54 . tested on single-database datasets by comparing the execution results of the predicted and the gold queries. We follow this methodology and filter the datasets to only use those question-query pairs for which execution accuracy evaluation is appropriate (see Suhr et al. (2020) for filtering details). To focus on evaluating the query structure, we replace predicted string literals with the most similar ones from the gold query (details of this procedure can be found in Appendix E). Of the 8 datasets that Suhr et al. (2020) consider we exclude ATIS, Advising, and Scholar for being too different from Spider and Restaurants for having just 27 examples after filtering. What remains are the SQL version of the GeoQuery dataset (Zelle and Mooney, 1996) as well as the small Academic, IMDB, and Yelp datasets (Finegan-Dollak et al., 2018). After filtering, these datasets are left with 532, 180, 107 and 54 examples, respectively. Note that these single-database datasets are partially contained in Spider. To avoid testing on training data, we train new models only on the about 7,000 examples produced by the Spider data collection effort. In this round of analysis we focus on the impact of CBSL and the underspecified FROM clause (SQLUF ) technique (Suhr et al., 2020). We expect both methods to be especially useful for out-of-distribution generalization, despite the limited importance that Spider evaluation attributes to them. The results in Table 5 show that, in line with our intuition, CBSL and SQLUF bring performance gains on 2 and 3 out of 4 datasets, respectively. To enable comparison with results by Suhr et al. (2020), we also report the results without literal replacement in Table 7. DuoRAT performs consistently better than the model by Suhr et al. (2020). Our investigations have revealed several possible simplifications of relation-aware text-to-SQL transformer models. In particular, we have shown that a transformer decoder with vanilla selfand memory-attention is sufficient, and that heuristic schema linking based on table and/or column names brings only a marginal benefit. To the contrary, we confirm the importance of grammar-constrained decoding, relational schema representations, content-based schema linking. Looking forward, we believe that content-based schema-linking will remain important, while the impact of name-based schema linking will further decrease as the language models get bigger and absorb more data. This prediction is based on the fact that the mapping from an entity to the entity type that name-based schema linking effectively performs can be highly domainand schema-specific. Last but not least, we have shown that predicting a more com-pact SQL version with an underspecified FROM clause improves the model's out-of-distribution performance, despite bearing little influence on the model's performance on Spider. In future work, we will combine the successful simplifications from this paper to build the simplest yet high-performing text-to-SQL model. One promising direction for further simplification is to use a pretrained encoder-decoder pair as proposed in Raffel et al. (2020) and Lewis et al. (2019).
abstain abstain method method method method abstain abstain abstain abstain abstain abstain other abstain method abstain result method method result objective abstain method abstain abstain other abstain abstain abstain method abstain abstain method method abstain abstain method abstain abstain abstain method abstain abstain abstain abstain abstain method method abstain abstain abstain abstain abstain method abstain method abstain method abstain abstain abstain method abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain result abstain abstain abstain other abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain abstain result abstain abstain abstain abstain abstain result result abstain abstain abstain abstain abstain abstain abstain result result result result method method abstain result method abstain