Abstract
Multivariate time series forecasting focuses on predicting future values based on historical context. State-of-the-art sequence-to-sequence models rely on neural attention between timesteps, which allows for temporal learning but fails to consider distinct spatial relationships between variables. In contrast, methods based on graph neural networks explicitly model variable relationships. However, these methods often rely on predefined graphs that cannot change over time and perform separate spatial and temporal updates without establishing direct connections between each variable at every timestep. Our work addresses these problems by translating multivariate forecasting into a "spatiotemporal sequence" formulation where each Transformer input token represents the value of a single variable at a given time. Long-Range Transformers can then learn interactions between space, time, and value information jointly along this extended sequence. Our method, which we call Spacetimeformer, achieves competitive results on benchmarks from traffic forecasting to electricity demand and weather prediction while learning spatiotemporal relationships purely from data.
Introduction
Predicting the future of complex systems—such as urban traffic flow or continental weather patterns—requires a deep understanding of both temporal dynamics (how variables evolve over time) and spatial dependencies (how different sensors or locations interact). Current state-of-the-art models typically prioritize one dimension over the other. Standard temporal Transformers group all variables at a single timestep into a single token, forcing them to share an attention pattern and obscuring distinct inter-variable relationships. Conversely, Spatiotemporal Graph Neural Networks (GNNs) explicitly model spatial relationships but often require a static, predefined graph that may not reflect real-world changes like road closures. Furthermore, many architectures alternate between spatial and temporal layers, creating information bottlenecks that prevent direct interaction between distant space-time points.
The Spacetimeformer Architecture
The core innovation of the Spacetimeformer is the "spatiotemporal sequence" formulation. Rather than processing a sequence of vectors, the model flattens the input data. For a system with $N$ variables and $L$ timesteps, the input is treated as a sequence of $L \times N$ individual tokens, where each token represents a single variable at a specific time.
Spatiotemporal Attention
By unrolling variables into separate tokens, the Transformer’s self-attention mechanism functions as a fully dynamic, learnable graph. This allows the model to learn direct dependencies between any two points in the spatiotemporal grid (e.g., Austin's temperature at 2 PM and New York's at 8 PM) without intermediate bottlenecks. This approach contrasts with traditional temporal attention or hybrid graph-temporal methods.
Embeddings and Scalability
To preserve context in the flattened sequence, the model utilizes specialized embeddings:
- Time2Vec: Captures periodic and seasonal patterns.
- Variable Embeddings: Learnable vectors identifying the source sensor.
- Position Embeddings: Identifying the temporal order.
Because flattening significantly increases sequence length (often exceeding 20,000 tokens), the Spacetimeformer employs the Performer (FAVOR+) mechanism. This "fast-attention" approach approximates the attention matrix in linear time and memory, overcoming the quadratic scaling limitations of standard Transformers.
Experimental Results
The Spacetimeformer was evaluated across diverse benchmarks, including highway traffic (Metr-LA, Pems-Bay), electricity demand (ETTm1), solar energy (AL Solar), and a new large-scale weather dataset (NY-TX Weather).
Key findings include:
- Graph-Free Performance: In traffic forecasting, the model matched the performance of specialized GNNs that utilized explicit road maps, despite the Spacetimeformer learning these spatial relationships entirely from data.
- Handling Complex Lags: On a "Shifted Copy" toy task, the model achieved a 17x reduction in error compared to temporal Transformers, which struggled to track multiple independent time lags across variables.
- Long-Horizon Forecasting: On the NY-TX Weather dataset, the Spacetimeformer significantly outperformed baselines as the prediction horizon extended to 160 hours.
Conclusion
The Spacetimeformer demonstrates that treating multivariate time series as a single spatiotemporal sequence allows Transformers to learn complex, dynamic relationships without predefined graphs or rigid architectural splits between space and time. While the increased sequence length presents engineering challenges, the use of linear attention mechanisms makes this approach feasible for large-scale forecasting. This architecture represents a step toward foundation models for time series, capable of generalizing across diverse datasets and domains.
Summary updated