## 2 Methods  
The inevitable change of arm length difference in interferometers of [PERSON] and Bob leads to the phase drift, which introduces further errors in \(X\) basis. Adopting machine learning technique to efficiently predict the phase drift instead of using the time-consuming scanning-and-transmitting program continually. We conduct supervised learning here to enable the LSTM network to extract phase drift information. A mass of data points should be collected for training the network before prediction, which is performed in advance. The whole data consists of the features and label of various time moments [24], including the operating temperature, the humidity, the intensity of a laser, the partially disclosed quantum bit error rate (QBER) of \(XX\) basis-pair, and five time-series displacement voltages, which can be obtained by running the MDI-QKD system with the traditional scanning-and-transmitting program. Moreover, the label is zero-phase voltage of the next moment. The data structure is illustrated in Figure 1. A newly added data feature, i.e., partially disclosed QBER of \(XX\) basis, can provide the LSTM network valuable running status, which directly increase prediction accuracy compared to the former data features [23]. The training data conclude 25 batches, and each batch consists of 5400 data points. The testing data conclude 3 batches and each batch has the same number of data points as the training data. Apart from that, we randomly extract one batch from training data and one batch from test data for cross validation check.  
Here, we design a two-layer LSTM network, which is illustrated in Figure 2, and utilize a mean squared error (MSE) cost function. This two-layer LSTM structure can extract temporal information from both coarse and fine granularity, which will help improve prediction accuracy, and detailed comparisons of different models are given in Appendix A. The number of hidden neurons in the first layer is 14 and the number of hidden neurons in the second layer is 9, which is obtained by prune. An unified Max-min normalization has been adopted for all data before input into the network. After the normalization, a  
Figure 1: Data structure of \(t\) moment. T, temperature; H, humidity; P, intensity of laser; Q, QBER of \(XX\) basis-pair; U, voltage.  
two-layer feedforward network with 9 neurons and 5 neurons is placed before the LSTM as an encoder for feature extraction and data denoising. The output of the second LSTM layer is input into a fully-connected layer, which decodes the output into the zero-phase voltage of the next moment and applies it to [PERSON]'s phase modulator (PM). We use [PERSON] as the optimization algorithm for 350 epochs, which takes approximately 40 min on our PC (CPU: Intel Core i7 9700@ 3.6 GHz; GPU: NVIDIA GeForce RTX 2080; RAM: DDR4 8 GBytes). The initial learning rate is 0.025, and it drops 70% every 100 epochs. Batch training is adopted. The final MSEs of training set, testing set, and validation set are 0.0533, 0.1131, and 0.881 respectively.  
Additionally, an updating process is added periodically for the long-term reliability of network forecasting, in which the scanning program will be operated after predicting for a certain time to eliminate the cumulative error in the prediction period [23]. As a result, the duty ratio of the present MDI-QKD system has been increased from 85.7% (transmitting: 30 s, scanning: 5 s) to 96.9% (transmitting: 540 s, mismatch events: 2 s, updating: 15 s).