# Few-Shot Knowledge Graph Completion Model Based on Relation Learning
## 4 Model
### Loss Function
In both datasets, relations with more than 50 but fewer than 500 associated triples are defined as few-shot relations (task relation \(\mathcal{R}_{task}\)), while the remaining relations related to these triples constitute the background knowledge graph \(\mathcal{G}^{\prime}\). Following the FKGC task setup, the task relations in NELL-One and Wiki-One are divided into training relations \(\mathcal{R}_{train}\), validation relations \(\mathcal{R}_{validation}\), and test relations \(\mathcal{R}_{test}\) in the proportions of \(51/5/11\) and \(133/16/34\), respectively. Detailed statistics of the datasets are presented in Table 2.

In this study, the Mean Reciprocal Rank (MRR) and Hits@n are used as evaluation metrics. MRR calculates the average of the reciprocals of the ranks of the correct answers. Higher MRR values indicate better model performance. Hits@n measures the proportion of correct answers appearing in the top n ranks. Similarly, higher Hits@n values indicate better model performance. In this experiment, \(n\) is set to 1, 5, and 10. Moreover, the size of the reference set (\(K\)) is set to 5, which means all models are evaluated on a five-shot knowledge graph completion task. ### Baseline Methods

To evaluate the effectiveness of the FRL-KGC model, two categories of benchmark models are selected for comparison: traditional knowledge graph embedding methods and FKGC methods. For the traditional knowledge graph embedding models, five models are chosen as control models: TransE [10], DistMult [12], ComplEx [13], SimplE [33], and RotatE [34]. During the training process of traditional knowledge graph embedding models, all triples from the background knowledge graph \(\mathcal{G}^{\prime}\) and the task relation set \(\mathcal{R}_{task}\) are used for training. The task relation set \(\mathcal{R}_{task}\) also includes the reference triples used in the validation and testing phases of the FKGC task. The FKGC models chosen for comparison in this study include GMatching [16], MetaR [19], FSRL [17], FAAN [18], and GANA [20]. Among them, GMatching is compared using GMatching (MaxP), which includes a neighborhood encoder and a matching processor and performs few-shot reasoning tasks through max pooling. MetaR is divided into two scenarios: MetaR (Pre-train) and MetaR (In-train). MetaR (Pre-train) trains entity embeddings using only the background knowledge graph, while MetaR (In-train) samples triples from the background knowledge graph and the original training set and includes them in the model training process. \begin{table}
\begin{tabular}{c c c c c c c c} \hline \hline
**Dataset** & **\# Ent.** & **\# Rel.** & **\# Triples** & \(\mathcal{R}_{task}\) & \(\mathcal{R}_{train}\) & \(\mathcal{R}_{validation}\) & \(\mathcal{R}_{test}\) \\ \hline NELL-One & 68,545 & 58 & 181,109 & 67 & 51 & 5 & 11 \\ Wiki-One & 4,838,244 & 22 & 5,859,240 & 183 & 133 & 16 & 34 \\ \hline \hline \end{tabular}
\end{table} 
Table 2: Statistics of datasets. # Ent. denotes the number of unique entities. # Rel. denotes the number of few-shot relations. \(\mathcal{R}_{task}\) denotes the number of relations we use as few-shot tasks. In the comparative experiments, both traditional knowledge graph embedding models and few-shot knowledge graph completion models were evaluated using their respective optimal parameter settings. The five-shot knowledge graph completion experiments were conducted five times, and the average of the results was taken as the final result. This approach ensures a fair comparison and provides a more reliable evaluation of the models' performance. ### Implementation Details

The FRL-KGC model is implemented using the PyTorch framework and the experiments are conducted on a single NVIDIA GeForce RTX 4090 GPU. The pretrained embedding model selected is the TransE model [10].