Deep Learning Community Question

How do Transformers compare to LSTMs for time-series forecasting?

Posted on 2024-05-20 • In Deep Learning • By Lisa Thompson

We are moving from traditional RNNs and LSTMs to Transformer-based architectures for our financial market predictions. While Transformers are great for NLP, are they actually better for sequential time-series data where the order of events is strictly linear and temporal? What are the trade-offs?

3 Answers 13,622 Views

All answers to this question 3 Answers

Nancy Carter Answered on 2024-05-22
Answered

The primary advantage of Transformers is the "Self-Attention" mechanism, which allows the model to look at the entire sequence simultaneously, capturing long-range dependencies that LSTMs often miss due to the sequential nature of their hidden state. However, Transformers don't have an inherent sense of order, so you must use "Positional Encoding" to give the model temporal context. For very long sequences, Transformers are faster because they allow for parallelization during training. LSTMs are still very competitive for smaller datasets or where the temporal patterns are relatively short-term and simple to capture.

Richard Scott Answered on 2024-05-24
Answered

That parallelization is a huge plus, but what about the "Informer" or "Temporal Fusion Transformer" variants? Are you planning to use the vanilla Transformer, or are you looking at these specific modifications that were designed to handle the multi-horizon forecasting challenges specific to financial data?

Lisa Thompson Commented on 2024-05-26
Commented

Richard, we are currently testing the Temporal Fusion Transformer (TFT). It’s performing better than our old LSTM because it handles static covariates (like stock symbols) and time-varying inputs much more elegantly. The attention weights also give us some level of interpretability, which our stakeholders really appreciate when we explain our model's predictions.

Kevin Parker Answered on 2024-05-28
Answered

Don't ignore the computational cost. Transformers have a quadratic complexity $O(n^2)$ relative to sequence length, which can be a bottleneck if you are trying to process high-frequency tick data in real-time.

Nancy Carter Commented on 2024-05-30
Commented

Great point, Kevin. We actually had to implement a "Sparse Attention" mechanism to keep our inference times under the required millisecond threshold for our high-frequency trading platform.

Write a Comment

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

Join the LearnersEra Community

Ask questions, share knowledge and learn from professionals across technology, project management and certification topics.

Change Country and Nearest City

Select your country and nearest city to see courses available in your region.