Deep Transformer Model with Pre-Layer Normalization for COVID-19 Growth Prediction

Coronavirus disease or COVID-19 is an infectious disease caused by the SARS-CoV-2 virus. The first confirmed case caused by this virus was found at the end of December 2019 in Wuhan City, China. This case then spread throughout the world, including Indonesia. Therefore, the COVID-19 case was designated as a global pandemic by WHO. The growth of COVID-19 cases, especially in Indonesia, can be predicted using several approaches, such as the Deep Neural Network (DNN). One of the DNN models that can be used is Deep Transformer which can predict time series. The model is trained with several test scenarios to get the best model. The evaluation is finding the best hyperparameters. Then, further evaluation was carried out using the best hyperparameters setting of the number of prediction days, the optimizer, the number of features, and comparison with the former models of the Long Short-Term Memory (LSTM) and Recurrent Neural Network (RNN). All evaluations used metric of the Mean Absolute Percentage Error (MAPE). Based on the results of the evaluations, Deep Transformer produces the best results when using the Pre-Layer Normalization and predicting one day ahead with a MAPE value of 18.83. Furthermore, the model trained with the Adamax optimizer obtains the best performance among other tested optimizers. The performance of the Deep Transformer also exceeds other test models, which are LSTM and RNN.

gression and classification were carried out using several datasets, which were then compared with other models. The results of this study showed that the TST model outperformed the average evaluation value for time series regression and time series classification. Furthermore, Zhou et al. [25] proposed the Informer, a long-sequence time-series forecasting (LSTF) model. The Informer model gets test results that exceed the LogTrans, Reformer, LSTMa, Long-and Short-term Time-series network (LSTnet) models, DeepAR, ARIMA, and Prophet.
Xiong et al. [21] experimented on the Transformer model [14] by comparing the position of the normalization layer and the warm-up stage of the learning rate model. From the experimental results, the original Transformer model that puts the normalization layer outside the residual block gets the expected value of the gradient from the parameter near the output layer, which is large at initialization and causes unstable training when using a large learning rate. Furthermore, it is found that the Transformer model with the normalization layer position in the residual block can be trained without a warm-up stage and converges more quickly.
There are several studies conducted to predict positive cases of COVID-19. One of them is a study by Yudistira [22] which uses multivariate Long Short-Term Memory (LSTM) to predict the growth of positive cases of COVID-19 in the world. In this study, several test scenarios were carried out and the results showed that the LSTM model could exceed the performance of ordinary Recurrent Neural Network (RNN) and Vector Auto Regression (VAR). Then, Yudistira et al. [23] analyzed which variables contributed to the time series prediction in COVID-19 cases. These variables include demographics, economy, health, government, education, environment, and COVID-19. The analysis was carried out by making a saliency map using gradient-based visual attribution for each variable and its time dimension. The results of the test obtained a saliency map to be able to understand what factors affect the increase or decrease of cases.
Based on the research results described previously, no studies predict the growth in the number of COVID-19 cases in Indonesia using the Deep Transformer model. Experimental research that compares the position of the normalization layer has only been carried out on the original Transformer model, not yet on the Transformer for time series prediction. Experiments for hyperparameter optimization have also not been carried out by all the previously described studies. Therefore, this study uses the Deep Transformer model [20] to predict the growth in the number of COVID-19 cases in Indonesia, compare the position of the normalization layer to the predicted results, and optimize several hyperparameters. The results of this study are expected to be helpful in various scientific fields in making decisions during this pandemic.
In this research, several test scenarios will be carried out. First, we test to get the best hyperparameters from the Deep Transformer model. The hyperparameters are the size of the model, the number of encoder and decoder blocks, the dimensions of the Feed-Forward Network, Pre-Layer, and Post-Layer, and the amount of time lag. Then, after obtaining the best hyperparameters, several advanced tests were carried out: testing the predictions for the next few days, testing the number of input features, and finally comparing them with the Recurrent Neural Networks (RNN) and Long Short-Term Memory (LSTM). This paper will be divided into several sections. Section 1 explains the introduction and background of conducting this research. Section 2 describes previous research that is similar to this study. Finally, section 3 describes the methods used in the research, starting with the normalization of the data used, the Deep Transformer model, Mean Absolute Percentage Error (MAPE) to calculate errors and related to the dataset.

Related Work
Research that has been done by Vaswani et al. [14] proposes a Transformer model that is used to perform language translation. The transformer is a model architecture that relies entirely on attention mechanisms to draw global dependencies between input and output. The Transformers enable significantly more parallelization and greatly improve translation quality after training for just twelve hours on eight P100 GPUs. The attention mechanism used is Scaled Dot-Product Attention and Multi-head Attention. Product Attention calculates the attention function on a set of queries simultaneously. Then it is entered into the matrix. Multi-head Attention allows the model to pay attention to information from different sub-spaces of representation at different positions.
Li et al. [8] conducted a study using the Transformer model for time series prediction. The research obtained satisfactory results, but there are two shortcomings: locality-agnostic and memory bottleneck. The first shortcoming can be overcome by the convolutional self-attention method, during the second shortcoming by the LogSparse method, so the proposed model name is LogSparse Transformer. This model is then compared with several popular models for time series prediction. These are Autoregressive Integrated Moving Average (ARIMA), Seasonal Error Trend (ETS), Temporally Regularized Matrix Factorization (TRMF), RNN-based autoregressive model (DeepAR), RNN-based state, and Space model (DeepState). It is found that the proposed model can exceed the performance of other models.
Furthermore, Wu et al. [20] also conducted research that developed a Transformer model so that it can be used to make time-series predictions. Furthermore, Zerveas et al. [24] conducted a study that developed the Transformer model into a Time Series Transformer (TST) model to predict multivariate time series. In this study, time series regression and time series classification were carried out using several datasets, which were then compared with other models such as Support Vector Regression (SVR), Random Forest, XGBoost, Rocket, LSTM, and several others. The TST model is divided into two tests: TST with supervised training and TST with unsupervised pre-training. The results of these tests showed that the average value of the evaluation for time series regression and time series classification was superior to the TST model with unsupervised pre-training and continued with TST with supervised training.
Furthermore, Zhou et al. [25] proposed a Transformer-based model that can predict a long sequence of time series or Long Sequence Time-series Forecasting (LSTF) called the Informer. This model applies the ProbSparse self-attention mechanism. The performance of the Informer was tested by comparing it with several models: LogTrans, Reformer, LSTMa, Long-and Short-term Time-series network (LSTnet), DeepAR, ARIMA, and Prophet. From the test results, it was found that the Informer model almost surpassed all the models tested.
Xiong et al. [21] experimented on the Transformer model by comparing the position of the normalization layer and the warm-up stage of the learning rate model. The experiment was carried out by combining the location of the normalization layer before or after the Transformer layer and using a warm-up stage, which is used or not on the translator machine. From the experimental results, the original Transformer model, which puts the normalization layer outside the residual block, gets the expected gradient value of the parameter near the output layer, which is large at initialization. Therefore, it causes unstable training when using a large learning rate. Furthermore, it is also found that the Transformer model with the normalization layer position in the residual block can be trained without a warm-up stage and converges more quickly.
Based on previous studies, it can be said that the Transformer model produces a time series prediction model with robust performance. This study conducts time-series predictions using the Deep Transformer model on Indonesia's daily growth dataset of COVID-19 data. Moreover, we assume that the position of the normalization layer influences the optimal parameters generated during learning.

Min-Max Normalization
Min-max normalization according to Patro and Sahu [11] is a scaling technique or mapping technique with the aim of creating a new range specifically with predetermined limits. Min-max normalization can be calculated using the formula in Equation 1. Variable A' is the min-max normalized data, A is the original data, D and C are the lower and upper ranges of the specified limits or can be written as [C,D].

Deep Transformer Model
Based on previous research by Wu et al. [20], the architecture of the Deep Transformer model follows the original architecture of the Transformer by Vaswani et al. [14]. Deep Transformer consists of two layers, those are encoder and decoder. Unlike the original architecture, in this model the input and output embedding layers are changed to input layers, which are fully connected layers (see Fig. 1). Encoder The encoder consists of an input layer, a positional encoding layer, and a stack of four identical encoder layers. At the input layer, input in the form of time series data is mapped into d dimensional vector model through a fullyconnected network. In this step, a multi-head attention mechanism is carried out which is an essential step for the model. The positional encoding stage is carried out using the sine and cosine functions which aim to encode sequential information in time series data by adding element-wised from the input vector to the positional encoding vector. The resulting vectors are then fed into the four encoder layers. Each encoder layer consists of two sub-layers, namely the self-attention sub-layer and the fully-connected feed-forward sub-layer. Each sublayer is followed by a normalization layer. The encoder generates d dimensional vector to proceed to the decoder [20].
Decoder The decoder consists of an input layer, one or several identical decoder layers, and an output layer. The input to the decoder starts from the last data point on the input of the encoder. At the input layer, the decoder input is mapped into a dimensional vector. In addition to the two sub-layers in each encoder layer, a third sub-layer is inserted in the decoder, namely the self-attention mechanism at the encoder output. Finally, there is an output layer which maps the output of the last decoder layer to the targeted time sequence. The decoder also uses look-ahead masking and a one-position offset between the decoder input and the target output in the decoder to ensure that the prediction of the time series data point only depends on the previous data point [20].
Positional Encoding Positional Encoding (PE) is entering some relative or absolute position information of each value in the sequence [14]. In this model, PE is added to the Pre-Layer and Post-Layer input embedding at the bottom of the encoder and decoder stack. PE has the same dimensions as the embedding, so they can be added together [20].
Multi Head Attention Attention is a function that maps a query and a set of key-value pairs to output. Query, key, value, and output are in vector form. The output value is calculated as the sum of the weights of the values. The weight for each value is calculated by a query function with the corresponding key [14,8,9]. Multi Head Attention is a module on the attention mechanism that calculates the Attention function several times in parallel. The output results from each head are combined by adding up the matrix values (concat) of each and linearly converted into the expected dimensions [14,8,9].
Based on the Deep Transformer model by Wu et al [20]. There are three types of Multi Head Attention, those are Multi-Head Self-Attention (MHSA), Multi-Head Causal-Attention (MHCA), and Encoder-Decoder Attention. MHCA is different from MHSA, where MHCA will do masking for the next prediction result, unlike MHSA where the value for each data is known. Then, in the Encoder-Decoder Attention key and value are obtained from the encoder results while the query is obtained from the MHCA results. Figure 1, it can be seen that between the sub-layers of the encoder and decoder layers there is an Add and Normalize layer [20]. The add layer is the residual connection layer [6], which is a skip-connection that learns the residual function by referring to the input layer, rather than studying the unreferenced function.

Residual Connection and Layer Normalization In
The normalization layer is designed to overcome the disadvantages of batch normalization [7] such as computationally expensive and batch size sensitive performance. Unlike batch normalization, layer normalization is a normalization method that directly estimates the normalization statistics from the inputs added to the neurons in the hidden layer so that normalization does not create new dependencies between training cases. The normalization layer can be calculated using Equation   where the normalization layer is placed between the residual connections, while in Pre-Layer Normalization (Pre-LN), the normalization layer is placed inside the residual connection (see Fig. 2). Xiong et al. [21] compared the performance of Pre-LN and Post-LN on language translation testing and found that the BLEU score and validation loss of the Pre-LN Transformer were better than post-LN. Furthermore, it was also found that Pre-LN converges faster than Post-LN and also found that changes in the position of the normalization layer affect changes in the optimizer.
Feed Fordward Networks Each layer on the encoder and decoder consists of fully connected feed-forward networks called Position-wise Feed-Forward Networks (FFN). Position-wise FFN is a network with a feed-forward layer consisting of two dense layers used in the last dimension, which means the same dense layer is used for each position item in an order called point-wise. Between the two dense layers, there is a ReLU activation function [14].

Recurrent Neural Networks
Recurrent Neural Networks (RNN) is a neural network architecture that aims to recognize patterns from sequence data. RNN can be used on time series data, genomes, handwriting, images and even to a higher level can be used in speech recognition. Mathematically, the hidden state and output of the RNN can be written in the form of an equation, those are Equation 5 and Equation 6.
The hidden state and the input at time t, respectively, are assumed to be H t and X t . Next, the weights will be used, those are W hh for the hidden state and W xh for input, while the bias will be b h . The output at time t is assumed to be O t with a weight of W ho and a bias of b o . Finally, the results of the calculations for both will be passed to the activation function φ such as logistic sigmoid or tanh.

Long Short-Term Memory
LSTM is a neural network that can handle vanishing gradient problems in RNN by using gated cells that can store information. In LSTM, there are three gates, namely input gate I t to read data into the cell, output gate O t to read cell entries, and forget gate F t to reset the contents of the cell. The three gates can be written into equations respectively in Equation 7, Equation 8, and Equation 9. The variables W xi , W xo , and W xf are the data weights of each gate. The variables W ho , W ho , and W hf are the hidden state weights of each gate. While the variables b i , b o , and b f are the bias. The calculation results from the three gates will be passed to the sigmoid activation function.
Next, there is a cellC t as a memory candidate which has the same calculation as before, but uses the activation function tanh. the calculation ofC t will use the weights W xc and W hc as well as the bias b c which can be seen in Equation 10. Finally, the value of the new memory will be calculated, namely C t and H t which can be seen in Equation 11 and Equation 12, where denotes elementwise multiplicationC

Mean Absolute Percentage Error
According to Adhikari and Agrawal [1], Mean Absolute Percentage Error (MAPE) is a performance measure to measure the performance of a time series prediction or forecasting model. It can be seen in Equation 13, MAPE represents the percentage of the average absolute error. The variable e is the error value of the prediction, y is the actual value, and n is the measure of the test data. The error value is obtained from the difference between the predicted value and the actual value.
M AP E = 1 n n t=1 e t y t * 100 (13)

Data
This study uses secondary data as the object of research. The data was taken from the public API on the official page of the COVID-19 Handling Task Force in Indonesia, that is covid.go.id. The data taken is in the form of a JSON (JavaScript Object Notation) file containing overall information on COVID-19 cases, daily updates, and accumulation from the beginning of the case to the present. The data will be normalized using min-max normalization with a value range of -1 to 1. The data is then divided into three, those are training data, evaluation data, and test data. Test data is the data used to test the model that has been trained. The test data were taken from the last 60 days of the total data. Training data is the data used to train the model and is determined as much as 70% of the data from the beginning except for test data. Evaluation data is used to evaluate the model in each epoch and is determined as much as 30% of the data from the back except for test data.

Experimental Results
The test was carried out on 750 initial COVID-19 data in Indonesia with the last 60 days used as test data. First, testing is carried out to obtain optimal hyperparameters. The hyperparameters are: embedding size; the number of encoder and decoder blocks; FFN, pre-layer, and post-layer dimensions; and the amount of time lag. Furthermore, further testing is carried out, those are testing the number of predictions for the next day, optimizer used in training, the number of features, and finally comparing the Deep Transformer model with the LSTM and RNN models.

Hyperparameter Testing
Prior to testing to obtain optimal hyperparameters, the initial hyperparameters are set as benchmarks or defaults, that is: input step or time lag of 7; predict step or the number of predictions ahead of 1; d size of 64; epoch maximum of 300; the number of encoders and decoders is 2 each; the number of heads from each encoder and decoder is 1; there are 50 hidden layers in feed forward, prelayer, and post-layer each; drop out on pre-layer, post-layer, and model is 0.2; the position of the normalized layer is Pre-LN; At the beginning of the training the learning rate is determined to be 1 and will decrease as the training is carried out. The optimizer used is the Adam optimizer with the LambdaLR scheduler with a function created by Wu et al. [20].
Testing on Embedding Size The first test was carried out to obtain the best d size among several sizes, those are 32, 64, 128, and 258. Table 1  Based on these test results, it was found that the best MAPE values for both types of normalized layers were equally obtained from the d size of 64. Therefore, the d size of 64 was used for advanced testing. Testing on the Number of Encoder and Decoder Blocks Furthermore, testing is carried out to obtain the best combination of the number of encoder and decoder blocks. The combination of the number of encoder and decoder blocks are 1-1, 2-2, 4-4, 2-4, and 4-2. Table 2 shows the result of the test. Based on the results of these tests, it was found that the combination of the number of encoder and decoder blocks which both amounted to 2 got the best MAPE value for the second type of normalization layer. Therefore, the number of encoder and decoder blocks used for advanced testing is 2.
Testing the Dimensions of the Feed Forward Network, Pre-Layer, and Post-Layer The next test combines the dimensions of the Feed Fordward Network layer, Pre-Layer, and Post-Layer. The size dimensions are either 30, 50, or 100. Table 3 shows the result of the test.
Based on the test results, it was found that the Pre-Layer with dimensions of 100 and the rest with dimensions of 50 got the best MAPE value for the Pre-LN model. Meanwhile, the best post-LN model yields the best performance using dimensions of FFN of 100 and the rest has dimensions of 50. Then the average is calculated for models with both normalization layers to determine which combination will be used for forthcoming testing. Finally, the best average is obtained for the FFN with the dimension of 100 and the remaining of 50.
Testing the Amount of Time Lag Next, the number of time lags was tested, which were 4, 7, 14, and 30 days. Table 4 is the result of testing the amount of time lag. Based on these results, it was found that the 7-day time lag got the best MAPE value for both types of normalized layers. Therefore, a time lag of 7 days was used for further testing.

Testing and Analysis of the Number of Predicted Days in the Future
After obtaining the best hyperparameters from the Deep Transformer model, further testing is carried out, testing the number of predictions for the next day. The test is performed using the d size of 64, the number of encoder and decoder blocks of 2 each, FFN dimension of 100, Pre-Layer and Post-Layer dimensions of 50, and the amount of time lag of 7 days. Then, judging from the previous four tests, the Pre-LN normalization layer got a better error value than the post-LN. Therefore, Pre-LN will be used for further testing. First, testing is carried out for predictions one day ahead of the last 60 days. The test was carried out ten times in a row and the average with its standard deviation of the error was calculated. The average MAPE value obtained is 22.298 and the standard deviation is 1.363. Figure 3 shows a graph comparing the average prediction results to the original value along with the range of prediction results from 10 trials. Second, testing is carried out for the next two days with the same data and method as the previous test. These tests obtained an average of 31.15 and a standard deviation of 2.901. The comparison of the average prediction results to the original value can be seen in Figure 4. Next, testing is carried out for the next four days with the same data and method as the previous test. These tests obtained an average of 37.428 and a standard deviation of 1.635. The comparison of the average prediction results to the original value can be seen in Figure 5. Furthermore, testing is carried out for the next 7 days with the same data and method as the previous test. From these tests, obtained an average of 42.35 and a standard deviation of 2.893. The comparison of the average prediction results to the original value can be seen in Figure 6. Based on the results of the four tests, it can be seen that the prediction error value for the next 1 day is the smallest and predictions for the next 2, 4, and 7 days will increase along with the increase in the number of predictions for the next day. Therefore, it can be said that the more days that will be predicted in the future, the resulting error value will increase. The comparison of the average error value and standard deviation can be seen in Table 5.

Testing and Analysis of the Optimizer Used
Furthermore, research was conducted on the optimizer used in training. The optimizers tested are Adam, AdamW, Adamax, Adagrad, Adadelta, SGD, and RMSprop. The hyperparameters used and the method of testing is the same as testing the predictions for the next day. For each optimizer, a LambdaLR scheduler is used with a function created by Wu et al. [20]. The results of comparing the MAPE values of the tested optimizer can be seen in Figure 7. In contrast, the graph of the comparison of the average prediction results with the ground-truth along with the range of the prediction results can be seen in Figure 8, Figure 9, Figure 10, Figure 11, Figure 12, Figure 13, and Figure 14.   Based on the results of the seven tests, it can be seen that the prediction error value using the Adamax optimizer is the smallest followed by Adam, AdamW, SGD, Adagrad, RMSprop, and the worst is the Adadelta optimizer. Therefore, it can be said that the Adamax optimizer can train the model better with a MAPE value of 22.343 compared to other optimizers. The comparison of the average error value and standard deviation can be seen in Table 6.

Testing and Analysis of the Number of Features
Furthermore, the number of features is tested, those are 1 feature (univariate) and multivariate with 3 features. One feature is using the number of positive cases, while three features are the number of positive cases, the number of deaths,     and the number of recoveries. Both tests have one output, that is the number of positive cases. The hyperparameters used are the same as the previous advanced tests. Testing is done by repeating the training and testing process several times for the last 60 days of data until the best results are obtained.  After several iterations of testing, the best result is that the model with one feature gets a MAPE value of 18.83, while the three features get a MAPE value of 25.24. The comparison graph between the prediction results and the original value of the prediction of one feature and 3 features, respectively, can be seen in Figure 15 and Figure 16.

Testing and Analysis of Other Models
Finally, a test was conducted to compare the Deep Transformer model with other models, those are Long Short-Term Memory (LSTM) and Recurrent Neural Network (RNN). The Deep Transformer model uses hyperparameters as before with a Pre-LN normalization layer, while the LSTM and RNN models use 16 hidden layers, one layer, 2000 epochs, and use the Adam optimizer with a learning rate of 0.01. Testing is carried out by conducting the training and testing process several times for the data for the last 60 days until the best results are obtained.
After several training and testing processes were carried out, the best MAPE results were obtained for each model. The Deep Transformer model got the best MAPE result of 18.83, the LSTM model got the MAPE result of 24.33, while the RNN model got the MAPE result of 23.15. A more detailed comparison of the MAPE values of each model can be seen in Figure 17, while a comparison of the prediction results for each model can be seen in Figure 18.  Based on the test results of the three models, it can be said that the Deep Transformer model outperforms the other two models by a considerable difference. The performance of the LSTM and RNN models is almost the same, but the RNN model is superior to LSTM with the same number of hidden layers.

Conclusion
The design of the Deep Transformer model in predicting the growth of COVID-19 cases in Indonesia starts by taking datasets from the public API on the official page of the COVID-19 Handling Task Force in Indonesia. Then, from the dataset, the required column is taken. Those are the date and the positive number of 750 days since the beginning of the case. Furthermore, the Deep Transformer model was developed in such a way that it could be used to predict the number of positive cases from the COVID-19 dataset in Indonesia. After the model is completed, training is carried out to obtain a model that can optimally predict positive cases by testing several existing hyperparameters. After obtaining the best hyperparameters, the testing process is carried out to predict the number of positive cases from the last 60 days of data. Finally, the test results will calculate the error value using Mean Absolute Percentage Error (MAPE).
Based on the results of several tests, the best hyperparameters were obtained. These are: embedding size of 64, the number of encoder and decoder blocks of two each, dimensions of the FFN of 100, Pre-Layer and Post-Layer dimensions are 50, the amount of time lag of 7 days, drop out on Pre-Layer of 0.2, the normalized layer of Pre-LN, and using the Adam optimizer of Adam with a learning rate initialization of 1. The loss will decrease as the training progresses with a total of 300 epochs. Using these hyperparameters, the Deep Transformer model gets a MAPE value of 18.83.
Suggestions for further experiments are comparing the results of model training with several optimizers other than Adam. Furthermore, developing a proper Deep Transformer model with more than one feature or multivariate input that can predict more than one day is promising.