# Relation-Aware Graph Transformer for SQL-to-Text Generation
## 1 Introduction
Typically, these leaf nodes convey significant semantic information in the query. Intermediate nodes such as SELECT and AND inherently capture the tree structure of the underlying SQL query and connect the scattered leaf nodes. An example of constructed SQL tree is shown in Figure 2.  
We introduce four types of relations into the SQL tree and propose two variants of cross-attention to capture the structural information. All relations are encoded by our proposed RGT model. As a SQL query may involve multiple tables, we first consider the relations among abstract concepts TABLE and COLUMN, called _database schema_ (DBS). Given two nodes representing TABLE or COLUMN, they might be two columns in the same table or two tables connected by a foreign key. We define 11 different types of DBS to describe such relations. Besides, the depth of node reflects the amount of information: deeper  
Figure 1: Two major problems incurred by the previous sparse Graph2 Seq model. Examples are selected from dataset Spider. (**a**) Poor generalization problem. \(K\) is the iteration number. Bold edges indicate the maximum distance between node pairs in the entire graph. (**b**) Ignorance of relations between node pairs. nodes contain more semantic information while shallower nodes have more syntactic information. We introduce _directional relative depth_ (DRD) to capture the relative depth between intermediate nodes. As for leaf nodes, the most important relation is affiliation. For example, in Figure 2, the leaf nodes _month_ and _salary_ are connected to the COLUMN node, and the COLUMN and another leaf node _val0_ belong to the intermediate node \(>\). These three leaf nodes are highly relevant. We use _lowest common ancestor_ (LCA) to measure the closeness of two leaf nodes. As we can see, the LCA of node _month_ and _val0_ is the node \(>\) in Figure 2. Furthermore, to leverage the tree structure of SQL, we use two cross-attention strategies, namely _attention over ancestors_ (AOA) and _attention over descendants_ (AOD). _Attention over ancestors_ only allows leaf nodes to attend their ancestors, and _attention over descendants_ forces intermediate nodes to attend only their descendants. We conduct extensive experiments on benchmarks WikiSQL [17] and Spider [18] with various baseline models. For simple SQL sketches on WikiSQL, our RGT model outperforms the previous best Graph2 Seq model [15] and achieves 31.2 BLEU. To the best of our knowledge, we are the first to perform SQL-to-text task on the SQL sketches that involves multiple tables and complex conditions. Results (28.84 BLEU) demonstrate that our model generalizes well compared with other alternatives. Our main contributions are summarized as follows:  
* We propose a relation-aware graph transformer to consider various relations between node pairs in the SQL graph. * We are the first to perform the SQL-to-text task with much more complicated SQL sketches on the dataset Spider. * Extensive experiments show that our model is superior to various Seq2 Seq and Graph2 Seq models. Data and codes of our models and baselines will be public. This paper is organized as follows: In Section 1, we introduce the task of SQL-to-text, analyze the existing problems of previous work and present our work on the whole. Then, we summarize related work in Section 2. After that, we clarify our method in detail in Section 3, including how to build the SQL tree and the architecture of our model. In Section 4, we conduct our experiments on two public datasets and report all the results. Finally, we conclude and show the expectation of future work in Section 5.