The Return of the Fallen: Transformers for Forecasting | by Nakul Upadhya | Could, 2023

Picture by Aditya Vyas on Unsplash

Introducing a brand new transformer mannequin: PatchTST

Currently, there was a big surge within the adoption of Transformer-based approaches. The outstanding achievements of fashions like BERT and ChatGPT have inspired researchers to discover the applying of this structure in varied areas, together with time sequence forecasting. Nonetheless, current work by researchers on the Chinese language College of Hong Kong and the Worldwide Digital Financial system Exercise confirmed that the implementations developed for this process had been lower than optimum and might be crushed by a easy linear mannequin on varied benchmarks [1].

In response, researchers at Princeton and IBM proposed PatchTST (Patched Time Sequence Transformer) of their paper A Time Series is Worth 64 Words [2]. On this paper, Nie et. al introduces 2 key mechanisms that carry transformers again to the forecasting enviornment:

  1. Patched consideration: Their consideration takes in giant elements of the time sequence as tokens as an alternative of a point-wise consideration
  2. Channel Independence: completely different goal sequence in a time sequence are processed independently of one another with completely different consideration weights.

On this submit, I intention to summarize how these two mechanisms work and talk about the implications of the outcomes found by Nie et. al [2].

Earlier than we dive into PatchTST, we have to first perceive the issues that Zeng et. al found with self-attention within the forecasting area. For these considering an in depth abstract, I extremely encourage studying the unique paper or the abstract I’ve written on their work:

In abstract, self-attention has a couple of key issues when utilized to the forecasting area. Extra particularly, prior time-series transformers had point-wise self-attention mechanisms the place every particular person time-stamp was handled as a token. Nonetheless, this has two foremost points. For one, this causes the eye to be permutation-invariant and the identical consideration values could be noticed should you had been to flip factors round. Moreover, a single timestamp doesn’t have plenty of info contained by itself and will get its significance from the timestamps round it. A parallel in language processing is that if we targeted on particular person characters as an alternative of phrases.

These issues led to a couple attention-grabbing outcomes when testing forecasting transformers:

  1. Transformers appeared extremely liable to overfitting on random patterns since including noise to the info didn’t lower the efficiency of the transformers considerably.
  2. Longer lookback intervals didn’t assist with the accuracy, indicating that the transformers had been unable to select up on important temporal patterns.

In an try to handle the problems that transformers have on this area, Nie et. al [2] launched two foremost mechanisms that differentiate PatchTST from prior fashions: Channel Independence and Patching.

In earlier works, all goal time sequence could be concatenated collectively right into a matrix the place every row of the matrix is a single sequence and the columns are the enter tokens (one for every timestamp). These enter tokens would then be projected into the embedding area, and these embeddings had been handed right into a single consideration layer

PatchTST as an alternative opts for Channel Independence the place every sequence is handed independently into the transformer spine (Determine 1.b). Which means each sequence has its personal set of consideration weights, permitting the mannequin to specialize higher. This method is often utilized in convolution networks and has been proven to considerably enhance the accuracy of networks [2]. Channel independence additionally permits the usage of the second mechanism: patching.

Determine 1: PatchTST Mannequin Overview (Determine from Nie et. al 2023 [2])

As talked about earlier than, attending on single time-steps is like attending on a single character. You find yourself dropping a way of order (“canine ”and “god” would have the identical consideration values with character-wise consideration) and likewise improve the reminiscence utilization of the mannequin at hand. So what’s the answer? We have to attend to phrases clearly!

Or extra precisely, the authors suggest to separate every enter time sequence up into fixed-length patches [2]. These patches are then handed by way of devoted channels because the enter tokens to the primary mannequin (the size of the patch is the token dimension) [2]. The mannequin then provides a positional encoding to every patch and runs it by way of a vanilla transformer [3] encoder.

This method naturally permits PatchTST to take native semantic info under consideration that’s misplaced with point-wise tokens. Moreover segmenting the time sequence considerably reduces the variety of enter tokens wanted, permitting the mannequin to seize info from longer sequences and dramatically lowering the quantity of reminiscence wanted to coach and predict [2]. Moreover, the patching mechanism additionally makes it viable to do representational studying on time sequence, making PatchTST an much more versatile mannequin [2].

Forecasting Experimental Outcomes

Determine 2: MSE & MAE outcomes on benchmarks. First place is bolded, second place is underlined. (Determine from Nie et. al 2023)

Of their paper, the authors check two completely different variations of PatchTST: one with 64 patches inputted into the mannequin (therefore the title) and one with 42 patches. The 42 patch variant has the identical lookback window as the opposite fashions, due to this fact it may be considered a good comparability to the opposite fashions. For each variants, a patch size of 16 and a stride of 8 had been used to assemble the enter tokens [2]. As seen in Determine 2, the PatchTST variants dominate the outcomes, with DLinear [1] profitable in a really small variety of circumstances. On common, PatchTST/64 achieved a 21% discount in MSE and a 16.7% discount in MAE. PatchTST/42 achieved a 20.2% discount in MSE and a 16.4% discount in MAE.

PatchTST represents a promising future for Transformer architectures within the time-series forecasting process, particularly as patching is a straightforward and efficient operator that may simply be carried out in future fashions. Moreover, the accuracy success of PatchTST signifies that time-series forecasting is certainly a fancy process that might profit from capturing complicated non-linear interactions.

  1. PatchTST Github repository:
  2. An implementation of PatchTST will be present in NeuralForecast:
  3. In case you are considering neural forecasting architectures that aren’t transformers, take into account studying my earlier article on Neural Foundation Evaluation Networks:

In case you are considering Forecasting, Deep Studying, and Explainable AI, take into account supporting my writing by giving me a comply with!


[1] A. Zeng, M. Chen, L. Zhang, Q. Xu. Are Transformers Effective for Time Series Forecasting? (2022). Thirty-Seventh AAAI Convention on Synthetic Intelligence.

[2] Y. Nie, N. H. Nguyen, P. Sinthong, and J. Kalagnanam. A Time Sequence is Price 64 Phrases: Lengthy-term Forecasting with Transformers (2023). Worldwide Convention on Studying Representations, 2023.

[3]A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A.N. Gomez, L. Kaiser, I. Polosukhin. Attention Is All You Need (2017). thirty first Convention on Neural Info Processing Methods.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button