## 2 Materials and Methods
### Proposed Method
#### 2.2.2 Model  
As shown in Figure 4, we propose a recurrent neural network based on the Bi-LSTM network and heartbeat-attention mechanism to classify sliding windows. It consists of four parts: Input Layer, LSTM Layer, Attention Layer, and Output Layer. Figure 4: Model Framework. Figure 3: Sliding Window. * Input Layer  
A sliding window with some unlabeled heartbeats is an input to the model. As shown in Figure 3, we assumed that the size of sliding windows was set as 10. At this time, \(\mathrm{T}=10\) in the input \(\mathrm{X[T]}\) means that the time step of Bi-LSTM network is 10, as shown in Figure 4. To ensure the dimension of input \(\mathrm{X[i]}\) (\(\mathrm{i}\in[1,\mathrm{T}]\)) was constant, we intercepted each heartbeat from one-third of the previous R-R interval and two-thirds of the next R-R interval, and resampled each heartbeat to 100 sample points. As the use of 12-lead ECG, the input \(\mathrm{X[i]}\) was converted to a heartbeat vector with a dimension of \(12*100\). * LSTM Layer  
The long short-term memory (LSTM) units were first proposed by [PERSON] et al. [PERSON] _et al._ (2016) based on recurrent neural networks. The gating mechanism is used to solve the problem of gradient vanishing. Subsequently, due to its good capability for sequence memory, LSTM units are widely used in the field of natural language processing. Some improved versions based on the LSTM units are also emerging. The basic LSTM units consist of four parts:  
Forget gate \(\mathcal{F}_{t}\): its expression is as (1),  
\[\mathcal{F}_{t}=\ \sigma\big{(}W_{f}\cdot[h_{t-1},x_{t}]+b_{f}\big{)} \tag{1}\]  
where \(\sigma\) is a sigmoid function, a forget gate controls how much memory state of previous step is forgotten. Input gate \(\mathcal{I}_{t}\): its expression is shown as (2) and (3),  
\[\mathcal{I}_{t}=\ \sigma(W_{i}\cdot[h_{t-1},x_{t}]+b_{i}) \tag{2}\]  
\[\widetilde{\mathcal{C}}_{t}=\ tanh(W_{c}\cdot[h_{t-1},x_{t}]+b_{c}) \tag{3}\]  
where \(\tilde{\mathcal{C}}_{t}\) is the state transition and \(tanh\) is a hyperbolic tangent function, a input gate determines how much input is retained. Memory state \(\mathcal{C}_{t}\): it is determined by the state transition \(\tilde{\mathcal{C}}_{t}\), input gate \(\mathcal{I}_{t}\) and forget gate \(\mathcal{F}_{t}\), as shown in (4). \[\mathcal{C}_{t}=\ \mathcal{F}_{t}\mathcal{C}_{t-1}+\mathcal{I}_{t}\widetilde{ \mathcal{C}}_{t} \tag{4}\]  
Output gate \(\mathcal{O}_{t}\): it controls how much the current unit output \(h_{t}\) (\(hf_{t}\) and \(hb_{t}\)) depends on the current memory state, and its expression is shown as (5) and (6). \[\mathcal{O}_{t}=\ \sigma(W_{o}\cdot[h_{t-1},x_{t}]+b_{0}) \tag{5}\]  
\[h_{t}= \mathcal{O}_{t}\cdot tanh(\mathcal{C}_{t}) \tag{6}\]  
Bi-LSTM networks [PERSON] _et al._ (2016) are introduced based on the basic LSTM units. As shown in Figure 4, the model includes forward (\(hf[i]\)) and backward (\(hb[i]\)) LSTM channels, which simultaneously capture past and future information. It can extract deep and robust features regarding classification tasks of time series. The output \(\mathcal{H}[i]\) of the \(i^{th}\) heartbeat is obtained by combining \(hf[i]\) and \(hb[i]\), as shown in (7). \[\mathcal{H}[i]=[hf[i]\oplus hb[i]] \tag{7}\]  
* Attention Layer  
The attention mechanism was first proposed in the field of visual image recognition, and is widely used in natural language processing. For example, [PERSON] et al. [PERSON] _et al._ (2016) introduced the attention mechanism to the machine translation for the first time and achieved excellent results. The attention mechanism, as the name suggests, was inspired by the performance of the human brain when it focuses on things, giving different weights to different parts of things. In the field of ECG diagnosis, doctors may pay more attention to abnormal heartbeats when analyzing patients' ECG records. Inspired by this trend, we propose a Bi-LSTM network based on the heartbeat-attention mechanism to detect myocardial infarction. The attention-based network is a measure of similarity.