Introducing Spectral Attention for Long-Range Dependency in Time Series Forecasting

Bong Gyun Kang, Dongjun Lee, HyunGi Kim, Dohyun Chung

Abstract

Sequence modeling faces challenges in capturing long-range dependencies across diverse tasks. Recent linear and transformer-based forecasters have shown superior performance in time series forecasting. However, they are constrained by their inherent inability to effectively address long-range dependencies in time series data, primarily due to using fixed-size inputs for prediction. Furthermore, they typically sacrifice essential temporal correlation among consecutive training samples by shuffling them into mini-batches. To overcome these limitations, we introduce a fast and effective Spectral Attention mechanism, which preserves temporal correlations among samples and facilitates the handling of long-range information while maintaining the base model structure. Spectral Attention preserves long-period trends through a low-pass filter and facilitates gradient to flow between samples. Spectral Attention can be seamlessly integrated into most sequence models, allowing models with fixed-sized look-back windows to capture long-range dependencies over thousands of steps. Through extensive experiments on 11 real-world time series datasets using 7 recent forecasting models, we consistently demonstrate the efficacy of our Spectral Attention mechanism, achieving state-of-the-art results.

Introduction: The Challenge of Long-Range Dependencies

In Time Series Forecasting (TSF), models typically operate on a fixed "look-back window"—often limited to 96 time steps—to predict future values. While increasing this window might seem intuitive, it leads to quadratic growth in memory and computational complexity, particularly for Transformer-based architectures.

Furthermore, standard deep learning practices involve shuffling data into mini-batches to ensure samples are independent and identically distributed (IID). However, time series data is inherently non-IID. Shuffling destroys the natural temporal link between consecutive samples, causing models to lose the "big picture" trends that span hours, days, or weeks.

Conventional training shuffles data, breaking temporal correlations, whereas the proposed method preserves them.

Methodology: Spectral Attention (SA)

To address these limitations, we introduce Spectral Attention (SA) and its parallelized counterpart, Batched Spectral Attention (BSA). These modules are designed to be "plug-and-play," integrating seamlessly into existing architectures like DLinear, iTransformer, or TimesNet with minimal overhead.

Frequency Filtering as Memory

Instead of attempting to store every raw data point, SA maintains an Exponential Moving Average (EMA) of model activations. This EMA acts as a low-pass filter, effectively distilling long-term trends. By employing multiple smoothing factors ($\alpha$), the model can simultaneously capture patterns at various scales, such as slow-moving seasonal trends and rapid daily fluctuations.

The Attention Mechanism

A learnable "Spectral Attention Matrix" allows the model to dynamically weight different frequency components—both low-pass trends and high-pass residuals—based on their importance for the current prediction task.

The Spectral Attention (SA) mechanism uses EMA and a learnable matrix to capture multi-scale dependencies.

Batched Spectral Attention (BSA)

To ensure efficiency on modern hardware, we "unfold" the EMA calculation across a mini-batch of consecutive samples. This technique, Batched Spectral Attention (BSA), allows gradients to flow backward through time across samples within a batch. This effectively extends the model's look-back window to the entire sequence of samples processed in that batch without increasing the raw input size.

Experimental Evaluation

We evaluated the efficacy of SA/BSA across 11 real-world datasets spanning weather, traffic, electricity, economy, health, and energy domains. Additionally, synthetic datasets with long-period sine waves (up to 1000 steps) were used to test the model's ability to capture dependencies far exceeding the standard 96-step window.

Key Insights and Results

  • Universal Performance Gains: BSA consistently improved performance across all 7 base models and 11 datasets, often establishing new state-of-the-art benchmarks.
  • Capturing Long-Range Trends: In synthetic tests, base models with a 96-step window failed to learn 1000-step trends. Integrating BSA allowed these models to capture such trends with high accuracy.
  • Efficiency: The computational overhead is remarkably low, typically adding less than 5% to training time, peak memory usage, and parameter count.
  • Robustness: The method demonstrates resilience against distribution shifts, a common challenge in real-world time series forecasting.

Conclusion and Future Work

Spectral Attention offers a computationally efficient way to bridge the gap between fixed-window inputs and long-range temporal dependencies. While its benefits are most pronounced in datasets with clear long-term trends, future work will explore more sophisticated frequency filtering techniques and the application of BSA to large-scale foundation models.

Summary updated

BibTeX
@inproceedings{kang2024introducing,
  author = {Bong Gyun Kang and Dongjun Lee and HyunGi Kim and Dohyun Chung},
  title = {{Introducing Spectral Attention for Long-Range Dependency in Time Series Forecasting}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=dxyNVEBQMp},
}
Figure