# Few-Shot Knowledge Graph Completion Model Based on Relation Learning
## 4 Model
### Loss Function  
This paper follows the model training settings of other FKGC methods [16]. Given a task relation \(r\in\mathcal{R}_{train}\) and its corresponding triplets, a reference set \(\mathcal{S}_{r}=\big{\{}(h_{i},t_{i})|(h_{i},r,t_{i})\in\mathcal{G}\big{\}}_{i}\) is constructed by randomly sampling \(K\) triplets from the triplet set, while B (batch_size) triplets are randomly sampled from the remaining triplets as the positive query set \(\mathcal{Q}_{r}=\big{\{}\left(h_{q},t_{q}\right)\big{|}\big{(}h_{q},r,t_{q} \big{)}\in\mathcal{G}\big{\}}\). As there are no negative triplets in the knowledge graph itself, a corresponding negative query set \(\mathcal{Q}_{r}^{-}=\Big{\{}\left(h_{q},t_{q}^{-}\right)\Big{|}\big{(}h_{q},r, t_{q}\big{)}\in\mathcal{G},\left(h_{q},r,t_{q}^{-}\right)\
otin\mathcal{G}\Big{\}}\) is constructed by replacing the tail entity of the triplets in \(\mathcal{Q}_{r}\). The hinge loss function is used for training, as shown in Equation (23):  
\[\mathcal{L}=\sum_{r}\sum_{(h_{q},t_{q})\in\mathcal{Q}_{r}}\sum_{(h_{q},t_{q}^{ -})\in\mathcal{Q}_{r}^{-}}\left[\gamma+\mathit{score}^{\prime}\Big{(}h_{q},t_ {q}^{-}\Big{)}-\mathit{score}^{\prime}\big{(}h_{q},t_{q}\big{)}\right]^{+} \tag{23}\]  
where \(\left[\cdot\right]^{+}=max(0,x)\) represents the standard hinge loss function, and \(\gamma\) is a margin hyperparameter used to separate positive and negative query triplets. Finally, this paper adopts the batch sampling-based meta training strategy proposed in Reference [17], which minimizes \(\mathcal{L}\) while optimizing the model parameter set. \(L_{2}\) regularization is applied to the model parameter set to avoid overfitting, and the Adam optimizer [32] is used to optimize the model. In summary, the training process of the model is shown in Algorithm 1. ``` Input: Training Task Set \(T_{meta-training}\), TransE knowledge graph embedding vector, Initialization parameter \(\theta\) of matrix model, Reference sample size; Output: Optimization parameters of the model \(W_{C}\lambda_{c}\theta\)
1 For epoch in 1 to M do
2 Shuffle(\(T_{meta-training}\)) // Disrupt tasks in \(T_{meta-training}\)
3 For \(T_{r}\) in \(T_{meta-training}\)do
4\(\mathcal{S}_{r}=\mathit{Sample}(r,K,\mathcal{G})\) // Extract entity pairs of relation \(r\) from \(K\)\(\mathcal{G}\) as a small sample reference set \(\mathcal{S}_{r}\)
5 For \(k\) in \(K\) do
6 Enhance the embedding vector representation of head and tail entities, and update the representation of few-show relations. 7 End For
8 Process triples through Transformer learners
9\(\mathcal{Q}_{r}=\mathit{Sample}(r,\mathcal{G})-\mathcal{S}_{r}\) // Build a regular triplet query set \(\mathcal{Q}_{r}\)
10\(\mathcal{Q}_{r}^{-}=\mathit{Pollute}(\mathcal{Q}_{r})\) // Pollute the tail entity of a positive triplet to obtain a negative triplet
11 Calculate matching scores
12 Accumulate the batch loss \(\mathcal{L}\)
13 Update \(\theta\) // Update \(\theta\) using the Adam optimizer
14 End for
15 End For

## 5 Experiments

In this section, link prediction experiments are conducted on the NELL-One and Wiki-One datasets, which are constructed with reference to [16], and the FRL-KGC model is compared with six few-shot knowledge graph completion models and five traditional models. Meanwhile, the performance of the models is evaluated on the basis of MRR, Hits@10, Hits@5 and Hits@1. ### Datasets and Evaluation Indicators

The two benchmark datasets used in this paper, NELL-One and Wiki-One, are commonly used datasets for few-shot knowledge graph completion tasks. NELL-One is constructed using the NELL dataset [4], which is a system that extracts structured information from web text and automatically expands and extends the knowledge graph. Wiki-One is a subset extracted from the Wikidata knowledge base [5].