# Authorship Detection on Classical Chinese Text Using Deep Learning
## 2 Data and Methods
### Bidirectional Long Short-Term Memory with an Attention Mechanism  
The LSTM network, an enhanced form of the recurrent neural network proposed by [PERSON] and [PERSON], is widely utilized for sequence labeling and classification of temporal sequences [31]. With sequential data as input, it captures state change over time. The structure of LSTM is well-designed to process long-sequence data and store information for long periods of time, avoiding gradient vanishing and gradient explosion. It is depicted in Figure 2.  
The core component of LSTM is the cell state, which acts like a conveyor belt, allowing information to flow carefully regulated by gates that selectively add or remove it. There are three gates in LSTM: forget gate, input gate, and output gate [32]. Each gate consists of a sigmoid neural net layer and a pointwise multiplication operation. The forget gate decides what information will be removed from the cell state, while the input gate determines what information will be stored in the cell state. After deleting and updating information in the cell state, the output gate controls what information will exit the cell state. Mathematically, the hidden state of each node can be expressed as  
Figure 2: LSTM structure. \[ \begin{split} f_{t}&=\sigma\Big{(}W_{f}x_{t}+U_{f}h_{t-1}+ b_{f}\Big{)}\\ i_{t}&=\sigma(W_{i}x_{t}+U_{i}h_{t-1}+b_{i})\\ u_{t}&=tanh(W_{u}x_{t}+U_{u}h_{t-1})+b_{u}\\ c_{t}&=f_{t}*c_{t-1}+i_{t}*u_{t}\\ o_{t}&=\sigma(W_{o}x_{t}+U_{o}h_{t-1}+b_{o})\\ h_{t}&=o_{t}*tanh(c_{t})\end{split}  \tag{2}\]  
\(f_{t}\) is the output of the forget gate. \(x_{t}\) is the input. \(h_{t-1}\) and \(h_{t}\) are the hidden state of layers. \(W\) is the weight, and \(b\) is the bias. \(\sigma\) is the logistic function. \(i_{t}\) is the output of the input gate. \(u_{t}\) is the intermediate state. \(c_{t-1}\) and \(c_{t}\) are the cell states of layers. \(o_{t}\) is the output of the output gate. In many natural language processing tasks, the current output depends on both the previous states and the future states. However, LSTM networks can only predict the next moment's output based on the sequence information from previous moments. BiLSTM is composed of forward and backward LSTM. Its structure is shown in Figure 3. The formula used is as follows:  
\[ \begin{split}\overset{\leftarrow}{h}_{t}&=LSTM \bigg{(}x_{t},\overset{\leftarrow}{h}_{t-1}\bigg{)}\\ \overset{\rightarrow}{h}_{t}&=LSTM\bigg{(}x_{t}, \overset{\rightarrow}{h}_{t-1}\bigg{)}\\ h_{t}&=w_{t}\overset{\rightarrow}{h}_{t}+v_{t}h_{t }+b_{t}\end{split}  \tag{3}\]  
where \(\overset{\leftarrow}{h}_{t}\), \(\overset{\rightarrow}{h}_{t}\), and \(h_{t}\) are the forward output, the backward output, and the present output of the network at time t, respectively. \(w_{t}\) and \(v_{t}\) are two weight matrices of the output. \(b_{t}\) denotes the offset. The attention mechanism in deep learning draws its inspiration from the selective attention in human vision. It aims to sift through a plethora of data to identify and prioritize the most relevant information for the task at hand, while sidelining the less relevant details. The core of the attention mechanism is the dynamic allocation of weight coefficients to each value, which are adjusted throughout the training process for each time step, determining the significance of each word in the context of the task. Authorship detection of DRC can be considered as a sequence annotation task. Deep learning requires a large number of samples for training, but for literary works, only a limited number of samples are available. Additionally, the chapter length of DRC is limited,  
Figure 3: BiLSTM structure. which makes it challenging to confirm the data type and sample length to input into BiLSTM for the authorship attribution [33]. It is important to reduce the length of the sample sequence and increase the number of samples. Assuming that the first few chapters of DRC were written by author A and the last few chapters by author B, we do not know exactly how many chapters author A or B wrote.