## 3 Methods
### Proposed Attention Mechanism  
According to our analysis, when there is a conflict in the polarity of emotional information within a sentence, the relative importance of these conflicting emotions is crucial for determining the overall polarity of the sentence. To fit this relationship, we propose an attention mechanism distinguished from other works. This mechanism uses an attention weight matrix to store the relative importance scores between input elements and then employs pooling techniques to select the attention distribution over each element. Figure 2 shows the attention generation process in this mechanism. First, on the input text domain representation \(h_{d}\) generated in the domain module and the hidden states \(H\) generated in the sentiment module, an attention matrix is created that reflects the relative importance of the input elements. This is obtained by comparing the elements at each moment with those at other moments, which is expressed as follows:  
\[s_{i,j}=f(g_{1}[h_{i},h_{d}]+g_{2}[h_{j},h_{d}]), \tag{14}\]  
where \(f\), \(g_{1}\) and \(g_{2}\) correspond to one-layer feed-forward neural networks that are used to merge domain information with hidden states at all time steps. \(h_{i}\) and \(h_{j}\) are concatenated with \(h_{d}\) to form domain-aware hidden states at times \(i\) and \(j\), respectively, then the hidden state at time \(i\) is used as the key point and compared with the hidden state at time \(j\) to generate a gate \(s_{i,j}\). Ideally, this value should be 0 or 1 to indicate whether \(i\) is selected after comparison. In our method, the activation function in \(f\) is set to Sigmoid to complete this function. After each hidden state is compared with other hidden states, a matrix \(S=\{s_{i,j};i,j=1,\ldots,n\}\) is generated. However, we note that in our method, the values in \(S\) are subject to a significant restriction; that is, the sum of \(s_{ij}\) and \(s_{\bar{i}}\) must be equal to 1, because if the \(i\)th element is selected between the \(i\)th element and the \(j\)th element, then the \(j\)th element cannot be selected, and vice versa. Accordingly, we assume that there are two triangular mask matrices, \(M^{upper}\) and \(M^{lower}\), which are expressed as follows:  
\[M^{upper} =\left\{ \begin{array}{ll}1,&\quad i\leq j,\\ 0,&\quad otherwise.\end{array} \right. \tag{15}\] \[M^{lower} =\left\{ \begin{array}{ll}0,&\quad i\leq j,\\ 1,&\quad otherwise.\end{array} \right. \tag{16}\]  
Next, the attention matrix is updated as follows:  
\[U=M^{\rm{upper}}\cdot S+M^{\rm{lower}}\cdot(J-S^{T}), \tag{17}\]  
where \(U=\{u_{i,j};i,j=1,\ldots,n\}\) is the updated attention matrix, \(S\) and \(S^{T}\) are the initial attention matrix and its transpose, \(J\) is the all-ones matrix, and \(\cdot\) denotes element-wise  
Figure 2: The process of generating attention weights and a text representation. multiplication. Through the above transformation, it can be ensured that in matrix \(U\), the sum of \(u_{ij}\) and \(u_{ji}\) is equal to 1, except for the elements on the diagonal. After that, \(U\) passes through a min-pooling layer and a Softmax layer to generate the attention probability distribution \(\{\alpha_{i};i=1,\ldots,n\}\). This step is crucial for our method, because the min-pooling layer is used to achieve the function of \"if one element cannot be more significant than others, it will not be the focus of attention\". When using other pooling layers such as a max-pooling layer or a mean pooling layer, this function is difficult to implement. The process is expressed in the following formula:  
\[a_{i}=min\text{-}pooling\{u_{i1},u_{i2},\ldots,u_{in}\}, \tag{18}\] \[\alpha_{i}=\frac{e^{a_{i}}}{\sum_{k=1}^{n}e^{a_{k}}}. \tag{19}\]  
where min-pooling is performed on the first dimension of the matrix to determine the importance of the \(i\)th element, represented by the attention weight \(a_{i}\). It is converted to \(\alpha_{i}\) through a Softmax transformation.