# Commonsense-Guided Inductive Relation Prediction with Dual Attention Mechanism
## 3 Methodology
### Experimental Configurations
#### 4.1.1 Datasets  
WN18 RR [33], FB18k-237 [34], and NELL-995 [35] are widely used in transductive link prediction. As for inductive relation prediction, we follow GraIL to conduct experiments based on the variants of WN18 RR, FB18k-237, and NELL-995, where entities in a test set are not contained in a train set. And every dataset induces four versions with increasing sizes.
```
0:\(KG\), target triple \((u,r_{t},v)\)
0: the Score of \((u,r_{t},v)\)
1: Extract subgraph \(G\) of target triple \((u,r_{t},v)\) from \(KG\)
2: Initialize node representation \(\mathbf{h}\) for all the nodes in \(G\)
3:for all k in K of GCN layers do
4: Update the embedding \(\mathbf{h}_{j}^{k}\) of each entity j at layer k
5: Calculate edge attention value \(\beta_{r,t}^{k}\) according to Equation (10)
6: Calculate relation attention value \(\gamma_{r,r_{t}}^{k}\) according to Equation (11)
7: Generate general attention \(\alpha_{(u,r,p)}^{k}\) according to Equation (12)
8: Update the embedding matrix \(\mathbf{H_{index(v)}^{k}}\) of all entities
9:endfor
10: Obtain entity embedding \(\mathbf{H_{L}}^{\prime}\) through BiGRU
11: Obtain \(\mathbf{h_{G}}\) through a readout function
12: Establish a Neighboring Relational Path Model to obtain path representation \(\mathbf{p}_{G}\) Equation (8)
13: Establish score function Score and loss function \(L_{sup}\) by Equations (3) and (4)
14: Update Score by commonsense re-ranking according to Equation (17)
15:return Score
```  
**Algorithm 1** The inductive process of the CNIA model  
The specific sampling method was divided into the following three steps: (1) Uniformly sample several root entities as root nodes in the original KGs; (2) Take the concatenated set of the multi-hop neighbors of the root node as the training KGs. To prevent the number of nodes from growing exponentially, the size of k needs to be limited; (3) Remove the sampled training set from the entire original KGs and then repeat Steps 1-2. Then, sample the test set so as to ensure that the entities in the test set are not included in the training set. The detailed statistics of the dataset are shown in Table 2.  
\begin{table}
\begin{tabular}{c c c c c c c c c c c c c} \hline \hline \multirow{2}{*}{**Version**} & \multirow{2}{*}{**Split**} & \multicolumn{4}{c}{**WN18 RR**} & \multicolumn{4}{c}{**FB15k-237**} & \multicolumn{4}{c}{**NELL-995**} \\  & & **\#R** & **\#E** & **\#TR1** & **\#TR2** & **\#R** & **\#E** & **\#TR1** & **\#TR2** & **\#R** & **\#E** & **\#TR1** & **\#TR2** \\ \hline \multirow{3}{*}{v1} & Train & 9 & 2746 & 5410 & 630 & 183 & 2000 & 4245 & 489 & 14 & 10,915 & 4687 & 414 \\  & Test & 9 & 922 & 1618 & 188 & 146 & 1500 & 1993 & 205 & 14 & 225 & 833 & 100 \\ \hline \multirow{3}{*}{v2} & Train & 10 & 6954 & 15,262 & 1838 & 203 & 3000 & 9739 & 1166 & 88 & 2564 & 8219 & 922 \\  & Test & 10 & 2923 & 4011 & 441 & 176 & 2000 & 4145 & 478 & 79 & 4937 & 4586 & 476 \\ \hline \multirow{3}{*}{v3} & Train & 11 & 12,078 & 25,901 & 3097 & 218 & 4000 & 17,986 & 2194 & 142 & 4647 & 16,393 & 1851 \\  & Test & 11 & 5084 & 6327 & 605 & 187 & 3000 & 7406 & 865 & 122 & 4921 & 8048 & 809 \\ \hline \multirow{3}{*}{v4} & Train & 9 & 3861 & 7940 & 934 & 222 & 5000 & 27,203 & 3352 & 77 & 2092 & 7546 & 876 \\  & Test & 9 & 7208 & 12,334 & 1429 & 204 & 3500 & 11,714 & 1424 & 61 & 3294 & 7073 & 731 \\ \hline \hline \end{tabular}
\end{table}
Table 2: The statistics of three inductive datasets. #E and #R, respectively, denote the number of entities and relations. #TR1 represents triples, which are utilized to form KG \(G\), while triples in #TR2 are utilized to evaluate.