# Relation-Aware Graph Transformer for SQL-to-Text Generation
## 3 Model
### Relations among Intermediate Nodes  
As for intermediate nodes, we consider two types of relations: _database schema_ (DBS) and _directional relative depth_ (DRD). DBS considers the relations among abstract concepts TABLE and COLUMN. In total, we define 11 relations, which is a subset of relations proposed in [PERSON] et al. [39]. For example, if node \(v_{i}^{l}\) and \(v_{j}^{l}\) are nodes of type COLUMN and they belong to the same table according to the database schema, the relation \(r_{ij}^{DBS}\) is Same-Table. Table 2 shows the complete version of DBS relations. Mathematically,  
\[r_{ij}^{DBS} =\text{DataBaseSchema}(v_{i}^{l},v_{j}^{l}),\] \[\mathbf{e}_{ij}^{DBS} =E_{rel}^{DBS}(r_{ij}^{DBS}),\]  
where the relation embedding function \(E_{rel}^{DBS}\) maps the relation category \(r_{ij}^{DBS}\) into a trainable vector \(\mathbf{e}_{ij}^{DBS}\).  
With the assistance of the underlying directed SQL tree, we can build another relation matrix to indicate the accessibility and relative depth difference between two intermediate nodes \(v_{i}^{l}\) and \(v_{j}^{l}\). Let \(d(v_{i}^{l})\) indicates the depth of node \(v_{i}^{l}\), e.g., the depth of root SQL node is 1 (see Figure 4). Given the maximum depth difference \(D\),  
\[clamp(i,j) =\text{max}(-D,\min(d(v_{i}^{l})-d(v_{i}^{l}),D)),\] \[r_{ij}^{DRD} =\begin{cases}clamp(i,j)&\text{if }v_{i}^{l}\to v_{j}^{l}\text{ or }v_{j}^{l}\to v_{i}^{l}\text{exists}\\ \inf&\text{otherwise}\end{cases},\] \[\mathbf{e}_{ij}^{DRD} =E_{rel}^{DRD}(r_{ij}^{DRD}),\]  
where \(E^{DRD}\) is the relation embedding module with \(2D+2\) entries. One special entry represents the inaccessibility inf.  
The complete relation embedding function \(E_{rel}^{I}\) and relation matrix \(R^{I}\) for intermediate nodes merge _database schema_ and _directional relative depth_ together.  
\[E_{rel}^{I}(r_{ij}^{I}) =\text{FC}([\mathbf{e}_{ij}^{DBS};\mathbf{e}_{ij}^{DRD}])\in \mathbb{R}^{d_{x}/H},\] \[r_{ij}^{I} =\text{tuple}(r_{ij}^{DBS},r_{ij}^{DRD}),r_{ij}^{I}\in R^{I},\]  
\begin{table}
\begin{tabular}{c c c c} \hline \multicolumn{2}{c}{**Node \(v_{i}^{l}\) and \(v_{j}^{l}\)**} & \multicolumn{2}{c}{**Relation \(r_{ij}^{DBS}\)**} & \multicolumn{2}{c}{**Description**} \\ \hline \multirow{4}{*}{COLUMN} & \multirow{3}{*}{COLUMN} & SAME-TABLE & \(v_{i}^{l}\) and \(v_{j}^{l}\) belong to the same table. \\  & & FOREIGN-KEY-COL-F & \(v_{i}^{l}\) is a foreign key for \(v_{j}^{l}\). \\  & & FOREIGN-KEY-COL-R & \(v_{j}^{l}\) is a foreign key for \(v_{i}^{l}\). \\ \hline \multirow{3}{*}{COLUMN} & \multirow{3}{*}{TABLE} & PRIMARY-KEY-F & \(v_{i}^{l}\) is the primary key of \(v_{j}^{l}\). \\  & & BELONGS-TO-F & \(v_{i}^{l}\) is a column of \(v_{j}^{l}\) (but not the primary key). \\ \hline \multirow{3}{*}{TABLE} & \multirow{3}{*}{COLUMN} & PRIMARY-KEY-R & \(v_{j}^{l}\) is the primary key of \(v_{i}^{l}\). \\  & & BELONGS-TO-R & \(v_{j}^{l}\) is a column of \(v_{i}^{l}\) (but not the primary key). \\ \hline \multirow{3}{*}{TABLE} & \multirow{3}{*}{TABLE} & FOREIGN-KEY-TAB-F & Table \(v_{i}^{l}\) has a foreign key column in \(v_{j}^{l}\). \\  & & FOREIGN-KEY-TAB-R & Same as above, but \(v_{i}^{l}\) and \(v_{j}^{l}\) are reversed. \\  & & FOREIGN-KEY-TAB-B & \(v_{i}^{l}\) and \(v_{j}^{l}\) have foreign keys in both directions. \\ \hline \multirow{3}{*}{others} & \multicolumn{3}{c}{NO-RELATION} & \(v_{i}^{l}\) and \(v_{j}^{l}\) have no above relations. \\ \hline \end{tabular}
\end{table}
Table 2: Database schema relation (refer to [PERSON] et al. [39]).  
where affine transformation \(\text{FC}(\cdot)\) is used to fuse relation features from two perspectives and tuple\((\cdot,\cdot)\) means the combination of relations.