# Adaptive Attentional Network for Few-Shot Relational Learning of Knowledge Graphs
## 4 Methods
### Entity-Enhanced Encoder  
The part extracts the hidden properties of entities through local graph structure. The existing work [32,33] has proved that constructing model modeling can improve the accuracy of actual prediction. HAF [8] has proved that a one-step neighborhood is helpful for entity prediction, but this framework does not consider the feature influence of the same relational attributes on the source entity under different training tasks. To address this issue, we design an adaptive weighted entity augmentation encoder. In order to gain the hidden attribute representation of \(H_{t_{k}}\) of the triple \((h_{k},r_{k},t_{k})\), this paper needs to address two weighting scenarios. The primary case is that the source entity  
Figure 2: Overview of the AAF framework. has the same distance neighbor entities; the second case is that the source entity has the same path and different distance neighbor entities. We first use the existing embedding-based model DistMult [15] for pre-training, and then the entity and relation embedding vectors are represented as follows:  
\[v_{h_{i}}=emb(h_{i}),v_{r_{i}}=emb(r_{i}),v_{t_{i}}=emb(t_{i}), \tag{2}\]  
where \(h_{i}\), \(r_{i}\), and \(t_{i}\) are the head entity, relation, and tail entity representing one of the triples, and \(v_{h_{i}}\), \(v_{r_{i}}\), and \(v_{t_{i}}\) represent the vector representation of the corresponding head entity, relation, and tail entity. Next, the triplet embedding vectors are concatenated into sequences \(x_{i}\), represented as shown in Equation (3). \[x_{i}=[v_{h_{i}},v_{r_{i}},v_{t_{i}}] \tag{3}\]  
Transformer models have been widely used in computer vision, computer recommendation, and natural language processing. The previous model [34] proves that the Transformer mechanism can more fully apply GPU parallel computing, and the Transformer can capture more sequence signals. The main structure is shown in Figure 3. This module first needs to obtain the sequence \(z^{0}=\left\{z^{0}_{1},z^{0}_{2},z^{0}_{3},\ldots,z^{0}_{k}\right\}\) through the sequence \(\left\{x_{1},x_{2},x_{3},\ldots,x_{k}\right\}\), as shown in Equation (4). \[z^{0}_{i}=x^{Input}_{i}+x^{PE}_{i}, \tag{4}\]  
where \(x^{Input}_{i}\) represents the vector representation of the sequence and \(x^{PE}_{i}\) represents the corresponding position embedding vector of the sequence triplet. After obtaining the zeroth layer sequence \(z^{0}\) representation, this chapter uses the Transformer encoder to obtain a new sequence, \(z^{L}=\left\{z^{L}_{1},z^{L}_{2},z^{L}_{3},\ldots,z^{L}_{k}\right\}\). The specific representation is shown in Equation (5). \[z^{L}_{i}=Transformer-Encoder(z^{L-1}_{i}),L=1,\ldots,K, \tag{5}\]  
where \(z^{L}_{i}\) represents the \(L\)-th hidden vector of \(z^{0}_{i}\). The multi-head attention mechanism is used in the Transformer encoder, and the calculation formula is shown in Equations (6) and (7). \[MultHead(Q,K,V)=Concat(head_{i},\ldots,head_{n})W^{0}, \tag{6}\]  
\[head_{i}=Self-Attention(QW^{Q}_{i},KW^{K}_{i},VW^{V}_{i}), \tag{7}\]  
where \(head_{i}\) represents the single-head self-attention mechanism, and n = 8 in the method in this chapter. The multi-head attention mechanism is composed of n single-head self-attention mechanisms. The parameter matrix \(W^{Q}_{i},W^{K}_{i},W^{V}_{i}\in R^{d_{model}\times d_{k}},W^{0}\in R^{nd_{k} \times d_{model}}\), \(d_{k}=d_{v}=\frac{d_{model}}{n}\) in Formula (7). \(Q\), \(K\), and \(V\) represent the three-element Query, Key, and Value of the self-attention mechanism. Figure 3: The main structure of the entity-enhanced encoder. Through the above process, this module can obtain the weighted implicit features of the entity's one-hop neighbors through the Transformer encoder, as shown in Equation (8). \[ \begin{split} Hek=Substring(\sum_{i=2}^{m}\alpha_{i}\times z_{i}^{L }),\end{split}