## 3 Model
### The Seq2 Seq Model Based on a Dictionary-Based Attention Mechanism  
The encoder part of the Seq2 Seq framework uses the bi-directional LSTM (Bi-LSTM) [24] model. We assume that given an input sequence \(X=(x_{1},\ x_{2},\ldots,x_{M})\), an output sequence \(Y=(y_{1},y_{2},\ldots,y_{N})\). At a certain time node \(t\), the encoder's hidden layer state \(h_{t}\) at the current time (\(t\)) is calculated by the hidden layer state \(h_{t-1}\) of the encoder at the time \(t-1\) and the current time input \(x_{t}\), as shown in Equations (1)-(3):  
\[\overset{\rightarrow}{ht}=LSTM(xt,ht\overset{\rightarrow}{-}1) \tag{1}\]  
\[\overset{\leftarrow}{ht}=LSTM(xt,ht\overset{\leftarrow}{-}1) \tag{2}\]  
\[ht=[\overset{\rightarrow}{ht;ht}] \tag{3}\]  
where \(\overset{\rightarrow}{ht}\overset{\leftarrow}{h_{t}}\) are the hidden layer states of the encoder \(t\) of the forward LSTM and the backward LSTM, respectively; and \(h_{t}\) is the hidden layer state of the encoder at the current moment. \(x_{t}\in R^{d}\) is the word embedding of \(x_{t}\), and \(d\) is the dimension of word embedding. Figure 1: A dynamic emotional session generation (DESG) model based on Seq2 Seq and a dictionary-based attention mechanism. In order to make the output sequence contain emotional information, we adopted a dictionary-based attention mechanism [25], which seamlessly \"inserts\" emotional words into the generated text at the correct time step. Specifically, first assume a given part of the input sequence and the generated output sequence, then find the emotional words in the sequence that are closely related to the words in the emotional dictionary. Calculate the weight of the dynamic influence on the emotional feature vector at the current moment, then seamlessly \"insert\" the desired emotional words into the output sequence. With this in mind, a unidirectional LSTM model based on a dictionary attention mechanism is adopted in the decoder part of the Seq2 Seq framework. The dictionary-based attention mechanism is shown in Figure 2.  
At a certain time node \(t\), the decoder updates the output \(s_{t}\) according to the generated output sequence word vector \(y_{t-1}\) and the context vector \(c_{t}\) based on the dictionary-based attention mechanism, as shown in Equation (4):  
\[st=LSTM([yt-1;ct];st-1) \tag{4}\]  
where \(s_{t}\) is the hidden layer state of the decoder, \(s_{0}=h_{M}\), and \(c_{t}\) is the embedding of \(c_{t}\). The context vector, which is based on the dictionary-based attention mechanism, is the weighted sum of the word embedding in \(V_{e}^{z}\) of the given emotion category \(z\), as shown in Equations (5)-(7):  
\[ct=\sum_{k}\alpha tk*w_{k}^{z} \tag{5}\]  
\[\alpha tk=\frac{\exp(ctk)}{\sum_{l=1}^{T_{z}}\exp(ctl)} \tag{6}\]  
\[ctk=Sigmoid(\alpha^{T}hM+\beta^{T}st-1+\gamma^{T}w_{k}^{z}) \tag{7}\]  
where \(w_{k}^{z}\) represents the \(k\)th word in \(V_{e}^{z}\), \(T_{z}\) is the number of words in emotion category \(z\), and \(\alpha\), \(\beta\), and \(\gamma\) are trainable parameters. We use the attention mechanism model proposed by [PERSON] et al. [26] to calculate the attention weight. For each emotional word in \(V_{e}^{z}\), the attention mechanism weight at time node \(t\) is determined by three parts: the hidden layer state at the \(t-1\) moment of the decoder, the encoding \(h_{M}\) of the input sequence, and the \(k\)th word in the embedding. Given the partial generated response and theinput post, the more relevant an emotional words, the more influence it will have on the emotion feature vector at the current time step. In this way, such lexicon-based attention leads to a higher probability of the emotional words being relevant to the current context. Figure 2: The Dictionary-based Attention Mechanism.