# Drilling Condition Identification Method for Imbalanced Datasets
## 4 BiLSTM-GRU-Based Classification Model for Drilling Conditions
### Model Principle  
#### 4.1.1 BiLSTM Model  
The long short-term memory (LSTM) network is an improved version of the recurrent neural network (RNN), specifically designed to handle time-series data and long-term dependencies. By introducing gating mechanisms, LSTM dynamically controls the retention and forgetting of information, effectively solving the issues of gradient vanishing or  
Figure 3: Sliding-window-based SMOTE processing flow.  
explosion that occur in traditional RNNs. This makes LSTM better suited for capturing information from long-term dependencies [31].  
The structure of the LSTM network consists of three gates, as shown in Figure 4:  
1. Forget gate (\(f_{t}\)): Determines the information to discard from the cell state. The input includes the previous hidden state (\(h_{t-1}\)) and the current input (\(X_{t}\)). After passing through a sigmoid function, the output value is between 0 and 1, where 0 means complete discarding and 1 means complete retention;
2. Input gate (\(i_{t}\)): Controls the update of new information. The sigmoid function selects which values should be updated, while the tanh function generates a candidate state (\(\widetilde{C}_{t}\)). The candidate state is then multiplied by the sigmoid result, and the result is added to the previous cell state (\(C_{t-1}\)) to update the current cell state (\(C_{t}\));
3. Output gate (\(o_{t}\)): Determines the output of the hidden state. The current cell state (\(C_{t}\)) is processed through the tanh function, and the result is multiplied by the output of the sigmoid function to generate the current hidden state (\(h_{t}\)), thereby considering both the current input and the long-term memory.  
The computational expressions for the LSTM network are as follows:  
\[f_{t}=\sigma\Big{(}W_{f}h_{t-1}+U_{f}X_{t}+b_{f}\Big{)} \tag{8}\]  
\[i_{t}=\sigma(W_{i}h_{t-1}+U_{i}X_{t}+b_{i}) \tag{9}\]  
\[o_{t}=\sigma(W_{o}h_{t-1}+U_{o}X_{t}+b_{o}) \tag{10}\]  
\[\widetilde{C}_{t}=tan\ h(W_{C}h_{t-1}+U_{c}X_{t}+b_{c}) \tag{11}\]  
\[C_{t}=f_{t}\times c_{t-1}+i_{t}\times\widetilde{C}_{t} \tag{12}\]  
\[h_{t}=o_{t}\times tan\ h(C_{t}) \tag{13}\]  
where \(\sigma\) is the sigmoid activation function. \(W_{f}\), \(W_{i}\), \(W_{o}\), \(W_{c}\) are the weight matrices for the gate units and state units. These matrices are used to linearly transform the previous hidden state \(h_{t-1}\). \(U_{f}\), \(U_{i}\), \(U_{o}\), \(U_{c}\) are the weight matrices for the gate units and state units. These matrices are used to linearly transform the current input \(X_{t}\). \(b_{f}\), \(b_{i}\), \(b_{o}\), \(b_{c}\) are the bias terms for the gate units and state units.  
The structure of the BiLSTM network is shown in Figure 5, consisting of a forward LSTM and a backward LSTM. The forward LSTM processes the input data in normal sequential order. For example, for the drilling sequence data \(X=(X_{0},X_{1},X_{2},\ \ldots,X_{T})\), the forward LSTM starts from \(X_{0}\) and calculates the forward hidden state \(h_{t}\) at time step \(t\), then  
Figure 4: LSTM network architecture.  
sequentially processes \(X_{1},X_{2},\ldots,X_{T}\). In contrast, the backward LSTM processes the input data in reverse order, starting from \(X_{T}\) and calculating the backward hidden state \(h_{t}\) at time step \(t\), then sequentially processes \(X_{T-1},X_{T-2},\ldots,X_{0}\). The output of the BiLSTM is obtained by concatenating the forward and backward hidden states. Specifically, for each time step \(t\), the output is \(Y_{t}=\left[\overset{\rightarrow}{h_{t}},\overset{\leftarrow}{h_{t}}\right]\). The BiLSTM model comprehensively considers both the past trends (forward) and future trends (backward) of sequence data, providing more comprehensive feature information for condition classification and prediction.