# A Spam Filtering Method Based on Multi-Modal Fusion
## 2 MMA-MF Model Architectures
### Text Classification Model: LSTM Model  
The structure of the LSTM model is roughly shown in Figure 2. It is composed of a one word embedded layer, two LSTM layers and one fully connected (FC) layer. The steps of handling the text portion of an email to obtain the classification probability value of the email are as follows: firstly using the preprocessing technique to acquire the text data of an email, then using the word embedding technique to get its word vector representation. In this paper, we select the word2 vec toolkit to get word vector representation. After that, we use the designed two LSTM layers to automatically extract features from the text data. Finally, we apply the FC layer with Softmax activation function to obtain the classification probability value of the text data as spam, and the LSTM model is trained and optimized by using the log-likelihood function to minimize the loss function [22]. For the hyperparameters of the LSTM model, we use the grid search optimization algorithm to select the optimal values for the five hyperparameters, which are learning rate, batch size, epochs, dropout rate and optimization algorithm. The range and optimal values of these hyperparameters selected by the LSTM model are shown in Table 1.  
We make a brief pseudo code description here for the LSTM model. For a detailed algorithm about the LSTM unit, please see the literature [10; 26]. Let \(T\) denote the text data of an email. Input \(T\) into the embedding step to convert \(T\) into becoming a word vector \(x\), \(x=(x_{1},x_{2},\cdots,x_{l})\), where \(x_{i}\in R^{n}\) is the n-dimensional word vectors for the \(i\)-th word in the document \(T\) and matrix \(x\in R^{lxn}\) denote the document \(T\), where \(l\) is the max length of and \(l\leq 500\). At time-step \(t\), the memory \(c_{t}\) and the hidden state \(h_{t}\) are updated with the following equations:  
\[ \begin{bmatrix}i_{t}\\ f_{t}\\ o_{t}\\ \hat{c}_{t}\end{bmatrix} = \begin{bmatrix}\sigma\\ \sigma\\ \sigma\\ tanh\end{bmatrix} W\cdot[h_{t-1},x_{t}], \tag{1}\]  
\[c_{t}=f_{t}\odot c_{t-1}+i_{t}\odot\hat{c}_{t}, \tag{2}\]  
\[h_{t}=o_{t}\odot tanh(c_{t}), \tag{3}\]  
where \(x_{t}\) is the input at the current time-step, \(i\), \(f\) and \(o\) is the input gate activation, forget gate activation and output gate activation, respectively, \(\hat{c}_{t}\) is the current cell state, \(\sigma\) denotes the logistic sigmoid function and \(\odot\) denotes element-wise multiplication. Through training and optimizing the \begin{table}
\begin{tabular}{c c c} \hline \hline
**Hyperparameter** & **Range** & **Optimal Value** \\ \hline learning rate & [0.001, 0.01, 0.1, 0.2] & 0.001 \\ batch size & [8; 16; 32] & 32 \\ epochs & [10; 20; 30] & 30 \\ dropout rate & [0.2, 0.3, 0.4] & 0.3 \\ optimization algorithm & [SGD [23], RMSprop [24], Adam [25]] & Adam \\ \hline \hline \end{tabular}
\end{table} 
Table 1: The range and optimal values of hyperparameters for LSTM. Figure 2: LSTM model framework. LSTM model, we could obtain the classification probability value of the text part as spam. The entire process of text spam classification algorithm is described in Algorithm 1. ```
0: Text Document T
0: Text spam classification probability value \(e\)
1: Input \(T\) into the word2 vec toolkit to get the word vector \(x\), \(x=(x_{1},x_{2},\cdots,x_{l})\). 2: For the first LSTM layer (64 LSTM units), input \(x\) at time \(t\) and complete the following calculations:

\[ \begin{bmatrix}i_{t}\\ f_{t}\\ o_{t}\\ \hat{c}_{t}\end{bmatrix} = \begin{bmatrix}\sigma\\ \sigma\\ \sigma\\ tanh\end{bmatrix} W\cdot[h_{t-1},x_{t}],\]

\[c_{t}=f_{t}\odot c_{t-1}+i_{t}\odot\hat{c}_{t},\]

\[h_{t}=o_{t}\odot tanh(c_{t}).\]
3: By the first LSTM layer, getting the text feature vector \(h=(h_{1},h_{2},\cdots,h_{64})\). 4: For the second LSTM layer(32 LSTM units), input \(h\) at time t and do the same as Equations (1)-(3). Finally, getting more abstract text feature vector \(k\), \(k=(k_{1},k_{2},\cdots,k_{32})\).