# FREDA: Few-Shot Relation Extraction Based on Data Augmentation
## 3 Methodology
### Interactive Attention Module  
Due to the limited number of instances in the support set and previous works ignoring the class information hidden in the query set, they failed to extract the inter-instance features well. Inspired by [PERSON] et al. [48], we interact the query set instances and relation triple instances, the query set instances, and support set instances by each other. This approach focuses on capturing highly interactive parts between instances to extract relation features better. Firstly, we use the Euclidean distance algorithm to calculate the similarity \(\alpha_{k}^{i}\) and \(\beta_{k}^{i}\) of the support set representation and query set representation, and the relation triple representation and query set representation. They are calculated as follows:  
\[\alpha_{k}^{i}=\frac{\sum_{j=1}^{G}\exp(S_{k}^{i}-Q_{j})^{2}}{\sum_{k=1}^{K} \sum_{j=1}^{G}\exp(S_{k}^{i}-Q_{j})^{2}}, \tag{9}\]  
\[\beta_{k}^{i}=\frac{\sum_{j=1}^{G}\exp(T_{k}^{i}-Q_{j})^{2}}{\sum_{k=1}^{K} \sum_{j=1}^{G}\exp(T_{k}^{i}-Q_{j})^{2}} \tag{10}\]  
where \(\alpha_{k}^{i}\) denotes the similarity of the \(k\)th instance of the \(i\)th relation in the support set to the query set, \(S_{k}^{i}\) denotes the embedding information of the \(k\)th instance of the \(i\)th relation in the support set, \(\beta_{k}^{i}\) denotes the similarity of the \(k\)th instance of the \(i\)th relation in the relation triple to the query set, \(T_{k}^{i}\) denotes the embedding information of the \(k\)th instance of the \(i\)th relation in the relation triple, and \(Q_{j}\) represents the embedding information of the \(j\)th instance of the query set. As shown in Figure 4, in the 2-way-2-shot setup, the information interaction between the support set and the query set, and the support set and the query set, obtain the similarity between them according to the inverse of the difference of the distances between the instances. Then, the similarity of the query set to the instances of the support set is calculated using Equation (9). Then, we directly multiply the similarity with the corresponding support set representation and relation triple representation. For example, in the support set, when the similarity of an instance is high it means that this instance contributes more to the model test to obtain the correct result, so we give it a higher coefficient. When multiplied together, the corresponding fused support set's relation prototype \(S^{\prime}\) and relation triple's relation prototype \(T^{\prime}\) are obtained:  
\[S^{\prime}=\sum_{k=1}^{K}\alpha_{k}^{i}\times S, \tag{11}\]  
\[T^{\prime}=\sum_{k=1}^{K}\beta_{k}^{i}\times T. \tag{12}\]  
The \(S\) is the embedding matrix of the support set after the encoder, and \(T\) is the embedding matrix of the relation triple after the encoder. We have obtained the relation prototype representation of the support set and the relation prototype representation of the relation triple after the information interaction. To present the algorithm of the interaction attention module more clearly, we summarize the experimental steps of the module through the following pseudocode of Algorithm 1. ```
Input: support set embedding \(S\in\mathbb{R}^{2d}\), query set embeddings \(Q\in\mathbb{R}^{2d}\) and relation triple information embedding \(T\in\mathbb{R}^{2d}\). Output: support set embedding \(S^{\prime}\) and query set embedding \(T^{\prime}\) after the interactive attention module
1:for episode n = 1 to 4 do
2:foreach\(S_{k}^{i}\in S\), \(Q_{j}\in Q\), \(T_{k}^{i}\in T\)do
3: use Equation (5) to calculate the similarity \(\alpha_{k}^{i}\) between each instance of the support set and the query set; use Equation (6) to calculate the similarity \(\beta_{k}^{i}\) between each instance of the relation triplet and the query set. 4: focusing on instances in the support set and relation triplet that are highly similar to the query set through Equations (7) and (8), we obtain \(S^{\prime}\) and \(T^{\prime}\)
5:endfor
6:endforeach
```  
**Algorithm 1** Dataset transformation steps in the Interactive Attention module