# Few-Shot Knowledge Graph Completion Model Based on Relation Learning
## 4 Model
### Relation Representation Encoder  
Through the above steps, the entities of the reference set and the query set are encoded to obtain their representations \(h\) and \(t\). Following the method in the FAAN paper [18], we can express the prototype relation \(r_{\rm s}\) of the reference set by connecting \(h_{\rm s}\) and \(t_{\rm s}\). As shown in Equation (7):  
\[r_{\rm s}\approx h_{\rm s}+t_{\rm s} \tag{7}\]  
MetaR [19] only represents few-shot relations by averaging the embeddings of all entity pairs in the support set, without considering the correlation between entity pairs in the reference set. Additionally, in previous methods, FSRL [17] simply used a cyclic autoencoder to aggregate a small reference set. However, as training deepens, the model's relation embeddings become overly reliant on entities, leading to relation overfitting and reduced generalization capability. In this paper, we utilize the neighbor relations of entity pairs in the reference set to enrich the semantic representation of the current relation and reduce the reliance on relation embeddings for entities, thereby enhancing the model's generalization ability. The main structure of the relation representation encoder is shown in Figure 4.  
In order to represent the neighbor relations of the head entity \(h_{i}\) and tail entity \(e_{i}\) of the _i-th_ entity pair \((h_{i},e_{i})\) in the reference set, we define the reference set entity pair neighbor relation set \(R^{\prime}_{r}=\mathcal{S}_{r}\{r|(h_{i},r,?),(e_{i},r,?)\in\mathcal{G}\}\). To enhance clarity, we represent the relation \(r\) in the set of neighbor relations as a vector, as shown in Equation (8):  
\[E_{r_{s,i}}=\{r,r\in\mathcal{S}_{r}\} \tag{8}\]  
where \(E_{r_{s,i}}\) represents the vectorized representation of the _i-th_ neighbor relation \(r_{\rm s}\) in the set \(R^{\prime}_{r}\). To enrich the semantic expression of the current relation while reducing the impact of noise, the dot product similarity of feature vectors is used to calculate the similarity between \(E_{r_{s,i}}\) and the reference set prototype relation \(r_{s}\). The calculation process is shown in Equation (9):  
\[E_{sim}(i)=r_{\rm s}\cdot E_{r_{s,i}}{}^{T} \tag{9}\]  
where \(E_{sim}(i)\) represents the vector similarity score of the _i-th_ neighbor relation \(r_{\rm s}\). Figure 4: The main structure of the relation representation encoder. In this paper, we only retain the T neighbor relations with the highest similarity scores. Therefore, a noise filtering method is used to filter out vectors with lower similarity scores, as shown in Equation (10):  
\[\mathbf{E}^{\prime}_{sim}(i)=\left\{ \begin{array}{ll}1,&\quad\text{if }E_{sim}(i)\in Top(\mathbf{E}_{sim}(i),T)\\ 0,&\quad\text{Otherwise}\end{array} \right. \tag{10}\]  
where the function \(Top(\cdot)\) returns the \(T\) neighbor relation vectors with the highest similarity scores in \(\mathbf{E}_{sim}(i)\) (T is set to 3). \(\mathbf{E}^{\prime}_{sim}(i)\) represents the neighbor relation vector after noise filtering. Next, the noise filtered neighbor relation vector \(\mathbf{E}^{\prime}_{sim}(i)\) is encoded, as shown in Equations (11) and (12):  
\[r^{\prime}_{s,i}=\sum W_{r_{s,i}}\cdot\mathbf{E}^{\prime}_{sim}(i) \tag{11}\]  
\[W_{r_{s,i}}=\frac{\exp(\lambda\cdot\sigma(\mathbf{E}^{\prime}_{sim}(i)))}{\sum_{s _{s,i}\in R^{\prime}_{s}}\exp(\lambda\cdot\sigma(\mathbf{E}^{\prime}_{sim}(i^{T})))} \tag{12}\]  
where \(r^{\prime}_{s,i}\) represents the representation after integrating the neighbor relation vector with the least noise in the reference set entity pairs; \(W_{r_{s,i}}\) represents the weight during the encoding process; \(\mathbf{E}^{\prime}_{sim}(i^{T})\) is the vector representation of each neighbor relation in the reference set entity pairs; \(\lambda\) is a learning parameter; and \(\sigma(\cdot)\) represents the activation function.