A T IME S ERIES IS W ORTH 64 W ORDS : L ONG - TERM F ORECASTING WITH T RANSFORMERS
Anonymous authors
Paper under double-blind review
A BSTRACT
We propose an efficient design of Transformer-based models for multivariate time series forecasting and self-supervised representation learning.
It is based on two key components: (i) segmentation of time series into subseries-level patches which are served as input tokens to Transformer; (ii) channel-independence where each channel contains a single univariate time series that shares the same embedding and Transformer weights across all the series.
Patching design naturally has three-fold benefit: local semantic information is retained in the embedding; computation and memory usage of the attention maps are quadratically reduced given the same look-back window; and the model can attend longer history.
Our channel-independent patch time series Transformer (PatchTST) can improve the long-term forecasting accuracy significantly when compared with that of SOTA
Transformer-based models.
We also apply our model to self-supervised pretraining tasks and attain excellent fine-tuning performance, which outperforms supervised training on large datasets.
Transferring of masked pre-trained representation on one dataset to others also produces SOTA forecasting accuracy.
I NTRODUCTION
Forecasting is one of the most important tasks in time series analysis.
With the rapid growth of deep learning models, the number of research works has increased significantly on this topic (Bryan &
Stefan, 2021; Torres et al., 2021; Lara-Ben ´ ıtez et al., 2021).
Deep models have shown excellent performance not only on forecasting tasks, but also on representation learning where abstract representation can be extracted and transferred to various downstream tasks such as classification and anomaly detection to attain state-of-the-art performance.
Among deep learning models, Transformer has achieved great success on various application fields such as natural language processing (NLP) (Kalyan et al., 2021), computer vision (CV) (Khan et al., 2021), speech (Karita et al., 2019), and more recently time series (Wen et al., 2022), benefiting from its attention mechanism which can automatically learn the connections between elements in a sequence, thus becomes ideal for sequential modeling tasks.
Informer (Zhou et al., 2021), Autoformer (Wu et al., 2021), and FEDformer (Zhou et al., 2022) are among the best variants of the Transformer model successfully applying to time series data.
Unfortunately, regardless of the complicated design of Transformer-based models, it is shown in the recent paper (Zeng et al., 2022) that a very simple linear model can outperform all of the previous models on a variety of common benchmarks and it challenges the usefulness of Transformer for time series forecasting.
In this paper, we attempt to answer this question by proposing a channel-independence patch time series Transformer (PatchTST) model that contains two key designs:
• Patching.
Time series forecasting aims to understand the correlation between data in each different time steps.
However, a single time step does not have semantic meaning like a word in a sentence, thus extracting local semantic information is essential in analyzing their connections.
Most of the previous works only use point-wise input tokens, or just a handcrafted information from series.
In contrast, we enhance the locality and capture comprehensive semantic information that is not available in point-level by aggregating time steps into subseries-level patches.
• Channel-independence.
A multivariate time series is a multi-channel signal, and each Transformer input token can be represented by data from either a single channel or multiple channels.
[Table]
Depending on the design of input tokens, different variants of the Transformer architecture have been proposed.
Channel-mixing refers to the latter case where the input token takes the vector of all time series features and projects it to the embedding space to mix information.
On the other hand, channel-independence means that each input token only contains information from a single channel.
This was proven to work well with CNN (Zheng et al., 2014) and linear models (Zeng et al., 2022), but hasn’t been applied to Transformer-based models yet.
We offer a snapshot of our key results in Table 1 by doing a case study on Traffic dataset, which consists of 862 time series.
Our model has several advantages:
Reduction on time and space complexity: The original Transformer has O ( N 2 ) complexity on both time and space, where N is the number of input tokens.
Without pre-processing, N will have the same value as input sequence length L , which becomes a primary bottleneck of computation time and memory in practice.
By applying patching, we can reduce N by a factor of the stride: N ≈ L/S , thus reducing the complexity quadratically.
Table 1 illustrates the usefulness of patching.
By setting patch length P = 16 and stride S = 8 with L = 336 , the training time is significantly reduced as much as 22 time on large datasets.
Capability of learning from longer look-back window: Table 1 shows that by increasing lookback window L from 96 to 336 , MSE can be reduced from 0 .
518 to 0 .
However, simply extending L comes at the cost of larger memory and computational usage.
Since time series often carries heavily temporal redundant information, some previous work tried to ignore parts of data points by using downsampling or a carefully designed sparse connection of attention (Li et al., 2019) and the model still yields sufficient information to forecast well.
We study the case when L = 380 and the time series is sampled every 4 steps with the last point added to sequence, resulting in the number of input tokens being N = 96 .
The model achieves better MSE score ( 0 . 447 ) than using the data sequence containing the most recent 96 time steps ( 0 . 518 ), indicating that longer look-back window conveys more important information even with the same number of input tokens.
This leads us to think of a question: is there a way to avoid throwing values while maintaining a long look-back window?
Patching is a good answer to it.
It can group local time steps that may contain similar values while at the same time enables the model to reduce the input token length for computational benefit.
As evident in Table 1, MSE score is further reduced from 0 .
397 to 0 .
367 with patching when L = 336 .
Capability of representation learning: With the emergence of powerful self-supervised learning techniques, sophisticated models with multiple non-linear layers of abstraction are required to capture abstract representation of the data.
Simple models like linear ones (Zeng et al., 2022) may not be preferred for that task due to its limited expressibility.
With our PatchTST model, we not only confirm that Transformer is actually effective for time series forecasting, but also demonstrate the representation capability that can further enhance the forecasting performance.
Our PatchTST has achieved the best MSE ( 0 . 349 ) in Table 1.
We introduce our approach in more detail and conduct extensive experiments in the following sections to conclusively prove our claims.
We not only demonstrate the model effectiveness with supervised forecasting results and ablation studies, but also achieves SOTA self-supervised representation learning and transfer learning performance.
R ELATED W ORK
Patch in Transformer-based Models.
Transformer (Vaswani et al., 2017) has demonstrated a significant potential on different data modalities.
Among all applications, patching is an essential part when local semantic information is important.
In NLP, BERT (Devlin et al., 2018) considers subword-based tokenization
(Schuster & Nakajima, 2012) instead of performing character-based tokenization.
In CV, Vision Transformer (ViT) (Dosovitskiy et al., 2021) is a milestone work that splits an image into 16 × 16 patches before feeding into the Transformer model.
The following influential works such as BEiT (Bao et al., 2022) and masked autoencoders (He et al., 2021) are all using patches as input.
Similarly, in speech researchers are using convolutions to extract information in sub-sequence levels from raw audio input (Baevski et al., 2020; Hsu et al., 2021).
Transformer-based Long-term Time Series Forecasting.
There is a large body of work that tries to apply Transformer models to forecast long-term time series in recent years.
We here summarize some of them.
LogTrans (Li et al., 2019) uses convolutional self-attention layers with LogSparse design to capture local information and reduce the space complexity.
Informer (Zhou et al., 2021) proposes a ProbSparse self-attention with distilling techniques to extract the most important keys efficiently.
Autoformer (Wu et al., 2021) borrows the ideas of decomposition and auto-correlation from traditional time series analysis methods.
FEDformer (Zhou et al., 2022) uses Fourier enhanced structure to get a linear complexity.
Pyraformer (Liu et al., 2022) applies pyramidal attention module with inter-scale and intra-scale connections which also get a linear complexity.
Most of these models focus on designing novel mechanisms to reduce the complexity of original attention mechanism, thus achieving better performance on forecasting, especially when the prediction length is long.
However, most of the models use point-wise attention, which ignores the importance of patches.
LogTrans (Li et al., 2019) avoids a point-wise dot product between the key and query, but its value is still based on a single time step.
Autoformer (Wu et al., 2021) uses autocorrelation to get patch level connections, but it is a handcrafted design which doesn’t include all the semantic information within a patch.
Triformer (Cirstea et al., 2022) proposes patch attention, but the purpose is to reduce complexity by using a pseudo timestamp as the query within a patch, thus it neither treats a patch as a input unit, nor reveals the semantic importance behind it.
Time Series Representation Learning.
Besides supervised learning, self-supervised learning is also an important research topic since it has shown the potential to learn useful representations for downstream tasks.
There are many non-Transformer-based models proposed in recent years to learn representations in time series (Franceschi et al., 2019; Tonekaboni et al., 2021; Yang & Hong, 2022;
Yue et al., 2022).
Meanwhile, Transformer is known to be an ideal candidate towards foundation models (Bommasani et al., 2021) and learning universal representations.
However, although people have made attempts on Transformer-based models like time series Transformer (TST) (Zerveas et al., 2021) and TS-TCC (Eldele et al., 2021), the potential is still not fully realized yet.
P ROPOSED M ETHOD 3. M ODEL S TRUCTURE
We consider the following problem: given a collection of multivariate time series samples with lookback window L : ( x 1 , ..., x L ) where each x t at time step t is a vector of dimension M , we would like to forecast T future values ( x L +1 , ..., x L + T ) .
Our PatchTST is illustrated in Figure 1 where the model makes use of the vanilla Transformer encoder as its core architecture.
Forward Process.
We denote a i -th univariate series of length L starting at time index 1 as x ( i ) 1: L = ( x ( i ) 1 , ..., x ( i ) L ) where i = 1 , ..., M .
The input ( x 1 , ..., x L ) is split to M univariate series x ( i ) ∈ R 1 × L , where each of them is fed independently into the Transformer backbone according to our channel-independence setting.
Then the Transformer backbone will provide prediction results ˆ x ( i ) =
(ˆ x ( i ) L +1 , ...,
ˆ x ( i ) L + T )
∈ R 1 × T accordingly .
Patching.
Each input univariate time series x ( i ) is first divided into patches which can be either overlapped or non-overlapped.
Denote the patch length as P and the stride - the non overlapping region between two consecutive patches as S , then the patching process will generate the a sequence
[Figure]
T r an s f o r m e r B a ck bone
Concatenate 𝑥 (%) ∈ ℝ ’×# ,𝑖 = 1,…,𝑀 +𝑥 (%) ∈ ℝ ’×( ,𝑖 = 1,…,𝑀 +𝑥 ∈ ℝ !
×(
[Figure]
×
[Figure]
Projection
[Figure]
of patches x ( i ) p ∈ R P × N
where N is the resulting number of patches, N =
⌊ ( L − P ) S ⌋ + 2 .
Here, we pad S repeated numbers of the last value x ( i ) L ∈ R to the end of the original sequence before patching.
With the use of patches, the number of input tokens can reduce from L to approximately L/S .
This implies the memory usage and computational complexity of the attention map are quadratically decreased by a factor of S .
Thus constrained on the training time and GPU memory, patch design can allow the model to see the longer historical sequence, which can significantly improve the forecasting performance, as demonstrated in Table 1.
Transformer Encoder.
We use a vanilla Transformer encoder that maps the observed signals to the latent representations.
The patches are mapped to the Transformer latent space of dimension D via a trainable linear projection W p ∈ R D
× P , and a learnable additive position encoding W pos ∈ R D × N is applied to monitor the temporal order of patches: x ( i ) d
= W p x ( i ) p + W pos , where x ( i ) d ∈ R D × N denote the input that will be fed into Transformer encoder in Figure 1.
Then each head h = 1 , ..., H in multi-head attention will transform them into query matrices Q ( i )
h
= ( x ( i ) d ) T W Qh , key matrices
K ( i ) h
= ( x ( i ) d ) T W Kh and value matrices V ( i )
h
= ( x ( i ) d ) T W Vh , where W Q h , W Kh ∈ R D × d k and
W Vh ∈ R D × D .
After that a scaled production is used for getting attention output
O ( i ) h ∈ R D × N :
[Equation]
i
[Equation]
The multi-head attention block also includes BatchNorm 1 layers and a feed forward network with residual connections as shown in Figure 1.
Afterwards it generates the representation denoted as z ( i
) ∈ R D × N .
Finally a flatten layer with linear head is used to obtain the prediction result ˆ x ( i ) =
(ˆ x ( i ) L +1 , ...,
ˆ x ( i ) L + T ) ∈ R 1 × T .
Loss Function.
We choose to use the MSE loss to measure the discrepancy between the prediction and the ground truth.
The loss in each channel is ∥ ˆ x ( i
) L +1:
L + T − x ( i ) L +1:
L + T ∥ 22 which is gathered and averaged over M time series to get the overall objective loss:
[Equation]
Instance Normalization.
This technique has recently been proposed to help mitigating the distribution shift effect between the training and testing data (Ulyanov et al., 2016;
Kim et al., 2022).
It simply normalizes each time series instance x
( i ) with zero mean and unit standard deviation.
In essence, we normalize each x ( i ) before patching and the mean and deviation are added back to the output prediction.
3. R EPRESENTATION L EARNING
Self-supervised representation learning has become a popular approach to extract high level abstract representation from unlabelled data.
In this section, we propose to apply PatchTST to obtain useful representation of the multivariate time series.
We will show that the learnt representation can be effectively transferred to forecasting tasks.
Among popular methods to learn representation via self-supervise pre-training, masked autoencoder has been applied successfully to NLP (Devlin et al., 2018) and CV (He et al., 2021) domains.
This technique is conceptually simple: a portion of input sequence is intentionally removed at random and the model is trained to recover the missing contents.
Masked encoder has been recently employed in time series and delivered notable performance on classification and regression tasks (Zerveas et al., 2021).
The authors proposed to apply the multivariate time series to Transformer, where each input token is a vector x
i consisting of time series values at time step i -th.
Masking is placed randomly within each time series and across different series.
However, there are two potential issues with this setting: First, masking is applied at the level of single time steps.
The masked values at the current time step can be easily inferred by interpolating with the immediate proceeding or succeeding time values without high level understanding of the entire sequence, which deviates from our goal of learning important abstract representation of the whole signal.
Zerveas et al.
(2021) proposed complex randomization strategies to resolve the problem in which groups of time series with different sizes are randomly masked.
Second, the design of the output layer for forecasting task can be troublesome.
Given the representation vectors z t ∈ R D corresponding to all L time steps, mapping these vectors to the output containing M variables each with prediction horizon T via a linear map requires a parameter matrix
W of dimension ( L · D ) ×
( M · T ) .
This matrix can be particularly oversized if either one or all of these four values are large.
This may cause overfitting when the number of downstream training samples is scarce.
Our proposed PatchTST can naturally overcome the aforementioned issues.
As shown in Figure 1, we use the same Transformer encoder as the supervised settings.
The prediction head is removed and a D × P linear layer is attached.
As opposed to supervised model where patches can be overlapped, we divide each input sequence into regular non-overlapping patches.
It is for convenience to ensure observed patches do not contain information of the masked ones.
We then select a subset of the patch indices uniformly at random and mask the patches according to these selected indices with zero values.
The model is trained with MSE loss to reconstruct the masked patches.
We emphasize that each time series will have its own latent representation that are cross-learned via a shared weight mechanism.
This design can allow the pre-training data to contain different number of time series than the downstream data, which may not be feasible by other approaches.
E XPERIMENTS 4. L ONG - TERM T IME SERIES FORECASTING
Datasets.
We evaluate the performance of our proposed PatchTST on 8 popular datasets, including
Weather, Traffic, Electricity, ILI and 4 ETT datasets (ETTh1, ETTh2, ETTm1, ETTm2).
These datasets have been extensively utilized for benchmarking and publicly available on (Wu et al., 2021).
The statistics of those datasets are summarized in Table 2.
We would like to highlight several large datasets: Weather, Traffic, and Electricity.
They have many more number of time series, thus the results would be more stable and less susceptible to overfitting than other smaller datasets.
[Table]
Baselines and Experimental Settings.
We use DLinear (Zeng et al., 2022), FEDformer (Zhou et al., 2022), Autoformer (Wu et al., 2021), Informer (Zhou et al., 2021), Pyraformer (Liu et al., 2022), and LogTrans (Li et al., 2019) as our baselines.
All of the models are following the same experimental setup with prediction length T ∈ { 24 , 36 , 48 , 60 } for ILI dataset and T ∈ { 96 , 192 , 336 , 720 } for other datasets as in the original papers.
We mainly cite their results from Zeng et al. (2022) with the default look-back window L = 96 for Transformer-based models, and L = 336 for DLinear.
But in order to avoid under-estimating the baselines, we also run FEDformer, Autoformer and Informer for six different look-back window L ∈ { 24 , 48 , 96 , 192 , 336 , 720 } , and always choose the best results to create strong baselines. More details about the baselines could be found in Appendix A.1.2.
We calculate the MSE and MAE of multivariate time series forecasting as metrics.
Model Variants.
We propose two versions of PatchTST in Table 3.
PatchTST/64 implies the number of input patches is 64, which uses the look-back window L = 512 .
PatchTST/42 means the number of input patches is 42, which has the default look-back window L = 336 .
Both of them use patch length P = 16 and stride S = 8 .
Thus, we could use PatchTST/42 as a fair comparison to DLinear and other Transformer-based models, and PatchTST/64 to explore even better results on larger datasets.
More experimental details are provided in Appendix A.1.
Results.
Table 3 shows the multivariate long-term forecasting results.
Overall, our model outperform all baseline methods.
Quantitatively, compared with the best results that Transformer-based models can offer, PatchTST/64 achieves an overall 21 . 0 % reduction on MSE and 16 .
7 % reduction on MAE, while PatchTST/42 attains a overall 20 . 2 % reduction on MSE and 16 .
4 % reduction on
MAE.
Compared with the DLinear model, PatchTST can still outperform it in general, especially on large datasets (Weather, Traffic, Electricity) and ILI dataset.
We also experiment with univariate datasets where the results are provided in Appendix A.3.
4. R EPRESENTATION LEARNING
In this section, we conduct experiments with masked self-supervised learning where we set the patches to be non-overlapped.
Otherwise stated, across all representation learning experiments the input sequence length is chosen to be 512 and patch size is set to 12 , which results in 42 patches.
We consider high masking ratio where 40% of the patches are masked with zero values.
We first apply self-supervised pre-training on the datasets mentioned in Section 4.1 for 100 epochs.
Once the pre-trained model on each dataset is available, we perform supervised training to evaluate the learned representation with two options: (a) linear probing and (b) end-to-end fine-tuning.
With (a), we only train the model head for 20 epochs while freezing the rest of the network; With (b), we apply linear probing for 10 epochs to update the model head and then end-to-end fine-tuning the entire network for 20 epochs.
It was proven that a two-step strategy with linear probing followed by fine-tuning can outperform only doing fine-tuning directly (Kumar et al., 2022).
We select a few representative results on below, and a full benchmark can be found in Appendix A.5.
Comparison with Supervised Methods.
Table 4 compares the performance of PatchTST (with fine-tuning, linear probing, and supervising from scratch) with other supervised method. As shown [Table]
underlined. [Table] in the table, on large datasets our pre-training procedure contributes a clear improvement compared to supervised training from scratch.
By just fine-tuning the model head (linear probing), the forecasting performance is already comparable with training the entire network from scratch and better than DLinear.
The best results are observed with end-to-end fine-tuning.
Self-supervised PatchTST significantly outperforms other Transformer-based models on all the datasets.
Transfer Learning.
We test the capability of transfering the pre-trained model to downstream tasks.
In particular, we pre-train the model on Electricity dataset and fine-tune on other datasets.
We observe from Table 5 that overall the fine-tuning MSE is lightly worse than pre-training and finetuning on the same dataset, which is reasonable.
The fine-tuning performance is also worse than supervised training in some cases.
However, the forecasting performance is still better than other models.
Note that as opposed to supervised PatchTST where the entire model is trained for each
[Table]
best are
[Table]
prediction horizon, here we only retrain the linear head or the entire model for much fewer epochs, which results in significant computational time reduction.
Comparison with Other Self-supervised Methods.
We compare our self-supervised model with
BTSF (Yang & Hong, 2022), TS2Vec (Yue et al., 2022), TNC (Tonekaboni et al., 2021), and TSTCC (Eldele et al., 2021) which are among the state-of-the-art contrastive learning representation methods for time series 2 .
We test the forecasting performance on ETTh1 dataset, where we only apply linear probing after the learned representation is obtained (only fine-tune the last linear layer) to make the comparison fair.
Results from Table 6 strongly indicates the superior performance of
PatchTST, both from pre-training on its own ETTh1 data (self-supervised columns) or pre-training on Traffic (transferred columns).
4. A BLATION STUDY
Patching and Channel-independence.
We study the effects of patching and channel-independence in Table 7.
We include FEDformer as the SOTA benchmark for Transformer-based model.
By comparing results with and without the design of patching / channel-independence accordingly, one can observe that both of them are important factors in improving the forecasting performance.
The motivation of patching is natural; furthermore this technique improves the running time and memory consumption as shown in Table 1 due to shorter Transformer sequence input. Channel-independence, on the other hand, may not be as intuitive as patching is in terms of the technical advantages.
Therefore, we provide an in-depth analysis on the key factors that make channel-independence more preferable in Appendix A.7.
More ablation study results are available in Appendix A.4.
Varying Look-back Window.
In principle, a longer look-back window increases the receptive field, which will potentially improves the forecasting performance.
However, as argued in (Zeng et al., 2022), this phenomenon hasn’t been observed in most of the Transformer-based models.
We also demonstrate in Figure 2 that in most cases, these Transformer-based baselines have not benefited from longer look-back window L , which indicates their ineffectiveness in capturing temporal information.
In contrast, our PatchTST consistently reduces the MSE scores as the receptive field increases, which confirms our model’s capability to learn from longer look-back window.
[Table]
C ONCLUSION AND F UTURE W ORK
This paper proposes an effective design of Transformer-based models for time series forecasting tasks by introducing two key components: patching and channel-independent structure.
Compared to the previous works, it could capture local semantic information and benefit from longer look-back windows.
We not only show that our model outperforms other baselines in supervised learning, but also prove its promising capability in self-supervised representation learning and transfer learning.
Our model exhibits the potential to be the based model for future work of Transformer-based forecasting and be a building block for time series foundation models.
Patching is simple but proven to be an effective operator that can be transferred easily to other models.
Channel-independence, on the other hand, can be further exploited to incorporate the correlation between different channels.
It would be an important future step to model the cross-channel dependencies properly.
A A PPENDIX A. E XPERIMENTAL D ETAILS A.1. D ATASETS
We use 8 popular multivariate datasets provided in (Wu et al., 2021) for forecasting and representation learning.
Weather 3 dataset collects 21 meteorological indicators in Germany, such as humidity and air temperature.
Traffic 4 dataset records the road occupancy rates from different sensors on San
Francisco freeways.
Electricity 5 is a dataset that describes 321 customers’ hourly electricity consumption.
ILI 6 dataset collects the number of patients and influenza-like illness ratio in a weekly frequency.
ETT 7 (Electricity Transformer Temperature) datasets are collected from two different electric transformers labeled with 1 and 2, and each of them contains 2 different resolutions ( minutes and 1 hour) denoted with m and
h. Thus, in total we have 4 ETT datasets: ETTm1 , ETTm2 ,
ETTh1 , and ETTh2 .
There is an additional Exchange-rate 8 dataset mentioned in the original paper, which is the daily exchange-rate of eight different countries.
However, financial datasets generally have different properties compared to time series datasets in other fields, for example the predictability.
It is well known that if a market is efficient, the best prediction for x t will be just x t − 1 (Fama, 1970).
Rossi (2013) argues that the toughest benchmark for exchange-rate forecasting is a random walk without drift.
Also, Zeng et al.
(2022) shows that by simply repeating the last value in the look-back window, the
MSE loss on exchange-rate dataset can outperform or be comparable to the best results.
Therefore, we are prudent in containing it into our benchmark.
A.1. D ETAILS OF B ASELINE S ETTINGS
The default look-back windows for different baseline models could be different.
For Transformerbased models, the default look-back window is L = 96 ; and for DLinear, the default look-back window is L = 336 .
The reason of this difference is that Transformer-based baselines are easy to overfit when look-back window is long while DLinear tend to underfit.
However, this can possibly lead to an under-estimation of the baselines.
To address this issue, we re-run FEDformer, Autoformer and
Informer by ourselves for six different look-back window L ∈ { 24 , 48 , 96 , 192 , 336 , 720 } .
And for each forecasting task (aka each different prediction length on each dataset), we choose the best one from those six results.
Thus it could be a strong baseline.
The ILI dataset is much smaller than the other datasets, so a different set of parameters is applied (the default look-back windows of Transformer-based models and DLinear are L = 36 and L = 104 respectively; we run FEDformer, Autoformer and Informer for six different look-back window
L ∈ { 24 , 36 , 48 , 60 , 104 , 144 } and choose the best results).
Time series has been an ancient field of study, with many traditional models developed, for example the famous ARIMA model (Box & Jenkins, 1970).
With the bloom of deep learning community, many new models were proposed for sequence modeling and time series forecasting before
Transformer appears, such as LSTM (Hochreiter & Schmidhuber, 1997), TCN (Bai et al., 2018) and
DeepAR (Salinas et al., 2020).
However, they are demonstrated to be not as effective as Transformerbased models in long-term forecasting tasks (Zhou et al., 2021; Wu et al., 2021), thus we don’t include them in our baselines.
A.1. M ODEL P ARAMETERS
By default, PatchTST contains 3 encoder layers with head number H = 16 and dimension of latent space D = 128 .
The feed forward network in Transformer encoder block consists of 2 linear layers with GELU (Hendrycks & Gimpel, 2016) activation function: one projecting the hidden representation D = 128 to a new dimension F = 256 , and another layer that project it back to
D = 128 .
For very small datasets (ILI, ETTh1, ETTh2), a reduced size of parameters is used ( H = 4 , D = 16 and F = 128 ) to mitigate the possible overfitting.
Dropout with probability 0 .
2 is applied in the encoders for all experiments.
The code will be publicly available.
A.1. I MPLEMENTATION D ETAILS
Although PatchTST processes channels in parallel which has to make multiple copies of the Transformer’s weights, the computation can be implemented efficiently and does not require any special operator.
The batch of samples of x ∈ R M × L with size B × M × L is passed through the patching operator to generate a 4 D tensor of size B × M × P × N which represents a batch of x ( i ) p ∈ R P × N in M series.
By reshaping the tensor to form a 3 D one of size ( B · M ) × P × N , this batch can be consumed by any standard Transformer implementation.
We further argue that our proposed PatchTST contains additional benefits: The components in Transformer backbone module shown in Figure 1 can differ across different input series, for instance the embedding layers and head layers.
Note that if the embedding layers are designed differently for each group of time series, the reshaping step will be applied after embedding.
Besides, the number of variables in the multivariate time series during the training may not need to match the number of series for testing.
This is especially beneficial for self-supervised pre-training where the pre-training data can have different number of variables from the fine-tuning data.
A. V ISUALIZATION
We visualize the long-term forecasting results of supervised PatchTST/42 and other baselines in
Figure 3.
Here, we predict 192 steps ahead on Weather and Eletricity datasets and 60 steps ahead on
Illness.
PatchTST provides the best forecasting both in terms of scale and bias.
A. U NIVARIATE F ORECASTING
Table 8 summaries the results of univariate forecasting on ETT datasets.
There is a target feature ”oil temperature” within those datasets, which is the univariate series that we are trying to forecast.
We cite the baseline results from (Zeng et al., 2022).
A. M ORE R ESULTS ON A BLATION S TUDY A.4. V ARYING P ATCH L ENGTH
This experiment studies the effect of patch lengths to the forecasting performance.
We fix the lookback window to be 336 and vary the patch lengths P =
The stride length is set [Table] the same as patch length, meaning no overlapping between patches.
The model is trained to predict 96 steps.
One observation from Figure 4 is that MSE scores don’t vary significantly with different choices of P , which indicate the robustness of our model against the patch length hyperparameter.
Overall, PatchTST benefits from increased patch length, not only in forecasting performance but also in the computational reduction.
The ideal patch length may depend on the dataset, but P between { 8 , 16 } seems to be general good numbers. scores with varying patch lengths P =
[2 , 4 , 8 , 12 , 16 , 24 , 32 , 40] where the lookback window is 336 and the prediction length is 96 .
A.4. V ARYING L OOK - BACK W INDOW
Here we provide a full benchmark of quantitative results in Table 9 for varying look-back window in supervised PatchTST/42 regarding Figure 2 in the main text.
Generally speaking, our model gains performance improvement with increasing look-back window, which show the effectiveness of our model in learning information from longer receptive field.
A.4. P ATCHING AND C HANNEL - INDEPENDENCE
Implementation Details.
For ablation study on patching and channel independence in section 4.3, we run different variants of PatchTST:
• Both patching and channel-independence are included in model (P+CI): this is the full PatchTST model that we have proposed in paper.
• Only channel-independence (CI): we simply set both patch length P and stride S to be 1 to avoid patching and only keep channel-independence.
• Only patching (P): referring to the implementation in A.1.5, instead of reshaping the 4 D tensor from B × M × P × N to ( B · M ) × P × N , we reshape it to B × ( M · P ) × N for channel-mixing with patching. [Table]
• Neither patching nor channel-independence is included (Original), which is just the original TST model Zerveas et al.
Note that the default number of maximum epochs for Electricity and Traffic datasets are reduced from 100 to 20 for ablation experiments due to the huge space and time complexity of the original time series Transformer and channel independent model (no patching).
Full Benchmark of Ablation Study.
The full benchmark is shown in Table 10, which is a completed version of Table 7 in the main text.
We can observe that patching together with channelindependence achieves the best results from the table, especially on larger datasets (Weather, Traffic, and Electricity) where the models are less susceptible to overfitting and thus the results would be more convincing.
As one can see the improvement is robust on both patching and channelindependence.
It is interesting to see that the improvement on ILI dataset is significant as well. A.4. I NSTANCE N ORMALIZATION
In this experiment, we perform analysis of the effect of the instance normalization.
We train two models PatchTST/64 and PatchTST/42 with and without using instance normalization and observe the evaluated scores. As indicated in Table 11, instance normalization improves the forecasting performance slightly on two models. However, even without instance normalization operator, PatchTST still outperforms other Transformer methods on most of the datasets. This is to confirm that the improvement mainly comes from patching and channel independence designs.
A. M ORE R ESULTS ON S ELF - SUPERVISED R EPRESENTATION L EARNING A.5. F ULL B ENCHMARK OF M ULTIVARIATE F ORECASTING
In this section we provide a full benchmark of multivariate forecasting results with self-supervised
PatchTST in Table 12, which is an extended version of Table 4. [Table]
[Table]
Although the models perform slightly better with instance normalization, compared to other Transformer models, the proposed approach achieve significantly better forecasting on most of the datasets even without instance normalization.
A.5. F ULL B ENCHMARK OF T RANSFER L EARNING
In this section we provide Table 13 which contains the results of pre-training on Electricity dataset then transferred to other 6 datasets.
Except Traffic data, the number of time series employed in the pre-training is much larger than the number of series during fine-tuning.
It is a full version with respect to Table 5 in the main text and more cogently proves the capability to do transfer learning using our PatchTST model. A. R OBUSTNESS A NALYSIS A.6. R ESULTS WITH D IFFERENT R ANDOM S EEDS
The results reported in the main text and appendix above are run with the fixed random seed 2021. To examine the robustness of our results, we train the supervised PatchTST model with 5 different random seeds: 2019, 2020, 2021, 2022, 2023 and calculate the MSE and MAE scores with each selected seed. The mean and standard derivation of the results are reported in Table 14. It is clear that the variances are considerably small which indicates the robustness against choice of random seeds of our model.
We also validate the self-supervised PatchTST model on different runs.
We pre-train the model once and fine-tune the model 5 times with different random batch selections.
The mean and standard derivation across different runs are also provided in Table 14.
We also observe that the variance is insignificant especially on large datasets while higher variance can be seen on smaller datasets.
[Table]
{+E TT m 
+}
[Table]
ETT
[Table]
[Table]
[Table]
ETT m
[Table]
[Table]
A.
R ESULTS WITH D IFFERENT M ODEL P ARAMETERS
To see whether PatchTST is sensitive to the choice of Transformer settings, we perform another experiments with varying model parameters.
We vary the number of Transformer layers L = { 3 , 4 , 5 } and select the model dimension D
= { 128 , 256 } while the inner-layer of the feed forward network is
F = 2 D .
In total, there are 6 different sets of model hyper-parameters to examine.
Figure 5 shows the MSE scores of these combinations on different datasets.
Except Illness dataset reveals high variance with different hyper-parameter settings, other datasets are robust to the choice of model hyper-parameters.
[Table]
[Figure]
forecast 96 steps.
Traffic reduce maximum number epochs to 50 to save computational time.
A. C HANNEL - INDEPENDENCE A NALYSIS
Intuitively, channel-mixing models should outperform the channel-independent ones since they have more flexibility to explore the cross-channel information, while with channel-independence the correlation is indirectly learnt via weight sharing.
However, this is contrast to what we have observed.
In Section A.7.1 we will provide an in-depth analysis on why channel-independence has better forecasting performance than channel mixing, and in Section A.7.2 we show that channel-independence is a general technique that can be used not only for PatchTST but also for the other models.
A.7. C HANNEL - INDEPENDENCE VS C HANNEL - MIXING
We find 3 key factors that makes channel-independent models more preferable:
• Adaptability: Since each time series is passed through the Transformer separately, it generates its own attention maps.
That means different series can learn different attention patterns for their prediction, as shown in Figure 6.
In contrast, with the channel mixing approach, all the series share the same attention patterns, which may be harmful if the underlying multivariate time series carries series of different behaviors.
Figure 6 reveals an interesting observation that the prediction of unrelated time series relies on different attention patterns while similar series can produce similar maps (e.g. series 11, 25, and 81 contain similar patterns while they are different from others).
We suspect this adaptability is one of the main reasons why PatchTST performs much better forecasting than Informer and other channel-mixing models.
• Channel-mixing models may need more training data to match the performance of the channelindependent ones.
The flexibility of learning cross-channel correlations could be a doubleedged sword, because it may need much more data to learn the information from different channels and different time steps jointly and appropriately, while channel-independent models only focus on learning information along the time axis.
We examine this assumption by experiments where we train the models with varying training data size and and the result is shown on left panel of Figure 7.
It is clear that channel-independent models converges faster against the size of training data.
As what we have observed in the figure and Table 2, the size of those widely used time series datasets may not be large enough for channel-mixing models to obtain similar performances in supervised learning.
• Channel-independent models are less likely to overfit data during training.
We record the MSE loss on test data and plot on the right panel of Figure 7.
Channel-mixing models show overfitting after a few initial epochs, while channel-independent models continue optimizing the loss with more training epochs.
The best trained models are determined by validation data, which are approximately the lowest points in the test loss curves.
It is clear that the forecasting performance of channel-independent models are better.
Furthermore we would like to comment on a few additional technical advantages of channelindependence: (1) Possibility of learning spatial correlations across series: Although we haven’t focused on this research in our paper, the channel-independence design can be naturally extended to learn cross-channel relationships by using methods like graph neural networks (Cao et al., 2020;
Chen et al., 2021).
(2) Multi-task learning where different loss types can be imposed on different time series where the same underlying Transformer model is shared.
(3) More robust to noise: If noise is dominant in one or several series, this noise will be projected to other series in the embedding space if we mix channels.
Channel independence can mitigate this problem by only retaining the noise in these noisy channels.
We can further alleviate the noise by introducing smaller weights to the objective losses that associate with noisy channels.
A.7. P ERFORMANCE OF C HANNEL - INDEPENDENCE ON O THER M ODELS
To show that channel-independence is a general technique that can be applied to the other models, we apply it to Informer (Zhou et al., 2021), Autoformer (Wu et al., 2021), and FEDformer (Zhou et al., 2022).
The results are shown in Table 15.
The channel-independent technique can improve the forecasting performance of those models generally.
Although they are still not able to outperform
PatchTST which is based on vanilla attention mechanism, we believe that more performance boost and computational reduction can be obtained with more advanced attention designs incorporating the channel-independence architecture.
[Table]
T r a f fi c
[Table]
[Table]
[Table]
it
[Table]
I
[Table]
I
[Table]
[Table]
[Table]
ETT h
[Table]
[Table]
[Table]
[Table]