# A Sentence-Matching Model Based on Multi-Granularity Contextual Key Semantic Interaction
## 3 Multi-Granularity Contextual Key Semantic Interaction Model
### Multi-Way Interaction Fusion Layer  
To capture the interaction information between sentences, the key semantic features \(\mathbf{S}^{S_{i}}\) and the attention-aware representation \(\mathbf{R}^{S_{i}}\) can be effectively integrated through three different comparison operations. These operations facilitate a deep interaction between the key semantic features of each sentence, enabling the integration of interaction information across different granularities, from low level to high level. The structure of the multi-way interaction fusion layer is illustrated in Figure 5.  
For sentence P, the three comparison operations are defined as follows:  
\[\mathbf{G}_{P_{1}}^{S_{i}}=FFN_{1}\Big{(}\Big{[}\mathbf{S}_{P}^{S_{i}},\mathbf{R}_{P}^{S_{ i}}\Big{]}\Big{)} \tag{21}\]  
\[\mathbf{G}_{P_{2}}^{S_{i}}=FFN_{2}\Big{(}\Big{[}\mathbf{S}_{P}^{S_{i}}-\mathbf{R}_{P}^{S_{ i}}\Big{]}\Big{)} \tag{22}\]  
\[\mathbf{G}_{P_{3}}^{S_{i}}=FFN_{3}\Big{(}\Big{[}\mathbf{S}_{P}^{S_{i}}\odot\mathbf{R}_{P}^ {S_{i}}\Big{]}\Big{)} \tag{23}\]  
where \(\mathbf{G}_{P_{1}}^{S_{i}}\in\mathbb{R}^{m\times 2h}\) (achieved through concatenation along the column direction), \(\mathbf{G}_{P_{2}}^{S_{i}}\in\mathbb{R}^{m\times h}\), and \(\mathbf{G}_{P_{3}}^{S_{i}}\in\mathbb{R}^{m\times h}\) represent the interaction features obtained after the three different operations:  
1. \(\mathbf{G}_{P_{1}}^{S_{i}}\) represents the concatenation of the key semantic features \(\mathbf{S}_{P}^{S_{i}}\) and the attention-aware representation \(\mathbf{R}_{P}^{S_{i}}\). In the interaction operation, concatenation is used to preserve all the information.
2. \(\mathbf{G}_{P_{2}}^{S_{i}}\) performs element-wise subtraction, approximating the calculation of Euclidean distance and measuring the relevance between the two representations using difference information.
3. \(\mathbf{G}_{P_{3}}^{S_{i}}\) performs element-wise multiplication, approximating the calculation of cosine similarity and measuring the similarity between the two representations.  
These comparison operations enhance semantic information and capture semantic relationships. To optimize the model's efficiency, a feed-forward neural network is employed to integrate the interaction information, resulting in the feature interaction matrix \(\mathbf{G}_{P}^{S_{i}}\in\mathbb{R}^{m\times l}\):  
\[\mathbf{G}_{P}^{S_{i}}=FFN_{4}\Big{(}\Big{[}\mathbf{G}_{P_{1}}^{S_{i}},\mathbf{G}_{P_{2}}^ {S_{i}},\mathbf{G}_{P_{3}}^{S_{i}}\Big{]}\Big{)} \tag{24}\]  
Figure 5: Structure of multi-way interactive fusion layer.  
where \(FFN_{1}\), \(FFN_{2}\), \(FFN_{3}\), and \(FFN_{4}\) denote distinct feed-forward neural networks with non-shared parameters, conventionally represented as follows:  
\[FFN(\mathbf{Z})=GELU(\mathbf{Z}\mathbf{W}+\mathbf{b}) \tag{25}\]  
and \(\left[\mathbf{G}_{P_{1}^{s}}^{S_{i}},\mathbf{G}_{P_{2}^{s}}^{S_{i}},\mathbf{G} _{P_{3}^{s}}^{S_{i}}\right]\in\mathbb{R}^{m\times 4h}\) is concatenated along the column dimension. The parameters \(\mathbf{W}_{4}\in\mathbb{R}^{4h\times l}\) and \(\mathbf{b}\in\mathbb{R}^{l}\) are adjustable, and \(l\) represents the output dimension of the network. This operation enables the model to capture deeper levels of interaction information and reduces the complexity of the representation. Likewise, the feature interaction matrix \(\mathbf{G}_{Q}^{S_{i}}\in\mathbb{R}^{n\times l}\) can be obtained for sentence \(\mathbf{Q}\).