# Few-Shot Knowledge Graph Completion Model Based on Relation Learning
## 3 Preliminaries
### Few-Shot Learning Settings  
According to Definition 1, few-shot knowledge graph completion is a relation-specific task. In the knowledge graph \(\mathcal{G}=\{(h,r,t)\subseteq\varepsilon\times\mathcal{R}\times\varepsilon\}\), the relation \(\mathcal{R}\) is divided into \(\mathcal{R}_{br}\) and \(\mathcal{R}_{task}\). \(\mathcal{R}_{br}\) represents the relation set in the background knowledge graph \(\mathcal{G}^{\prime}\), which is a subgraph of the knowledge graph \(\mathcal{G}\) obtained by removing all task relations. \(\mathcal{R}_{task}\) represents the task relation set including \(\mathcal{R}_{train}\), \(\mathcal{R}_{validation}\), and \(\mathcal{R}_{test}\), which are used in the meta training, meta validation, and meta testing stages of the FKGC task, respectively.  
In the meta training stage, for each training task \(r\in\mathcal{R}_{train}\), the associated triplets are randomly divided into a reference set \(\mathcal{S}_{r}\), a query set \(\mathcal{Q}_{r}\), and a set \(\mathcal{D}_{r}=\{\mathcal{S}_{r},\mathcal{Q}_{r}\}\). The reference set \(\mathcal{S}_{r}=\{\,(h_{i},t_{i})|(h_{i},r,t_{i})\in\mathcal{G}\}_{i}\) contains \(K\) entity pairs \((h_{i},t_{i})\). The query set \(\mathcal{Q}_{r}=\left\{\left(h_{j},t_{true}/C_{h_{j},r}\right)\right\}_{j}\) consists of the true tail entity \(t_{true}\) of the query triplet and a candidate tail entity set \(C_{h_{j},r}\). The candidate tail entities for each triplet in the query set are constructed based on entity type constraints [18]. This construction method ensures that the query triplets will be matched with semantically similar candidate tail entities. Finally, all the query tasks are combined into a set \(T_{mtr}=\{\mathcal{D}_{r}\}\). For each query triplet \((h,r,?)\in\mathcal{Q}_{r}\), the similarity scores between the candidate entity pairs \((h_{j},C_{h_{j},r})\) and all reference entity pairs \((h_{i},t_{i})_{i}\in\mathcal{S}_{r}\) are computed. The candidate entity with the highest-ranking score is selected as the training result.  
In the meta testing stage, the overall procedure is similar to the meta training stage. Firstly, the associated triplets of the test task \(r^{\prime}\in\mathcal{R}_{test}(\mathcal{R}_{train}\cap\mathcal{R}_{test}= \varnothing)\) are randomly divided into a reference set \(\mathcal{S}^{\prime}_{r}\) and a query set \(\mathcal{Q}^{\prime}_{r}\) to define \(\mathcal{D}^{\prime}_{r}=\{\mathcal{S}^{\prime}_{r},\mathcal{Q}^{\prime}_{r}\}\). Secondly, all the test query tasks are combined into a meta test set, denoted as \(T_{mte}=\{\mathcal{D}^{\prime}_{r}\}\). Finally, the candidate entities are scored, and the candidate entity with the highest score is selected as the predicted result of the model. In summary, the FKGC task involves ranking the true tail entity \(t_{j}\) and candidate tail entity \(t^{\prime}\in C_{h_{j},r}\) of a triple \((h_{j},r,?)\). Given the task relations in set \(r\), the information provided by the knowledge graph \(\mathcal{G}\), and the reference set \(\mathcal{S}_{r}\), the objective is to ensure that the rank of \(t_{j}\) is higher than that of all the candidate entities.  
Figure 1 illustrates an example of a five-shot KGC task. In the few-shot KGC task, the reference set for the query triplet (Windows, ProducedBy,?) consists of five associated triplets. The goal is to use the reference set to match the correct tail entity for the query triplet (Windows, ProducedBy,?). In this case, the true tail entity \"Microsoft\" should be ranked higher than other entities. The core of the FKGC task lies in predicting new facts with minimal reference information.