Abstract
Spatiotemporal data is ubiquitous, and forecasting it has important applications in many domains. However, its complex cross-component dependencies and non-linear temporal dynamics can be challenging for traditional techniques. Existing methods address this by learning the two dimensions separately. Here, we introduce Temporal Graphormer (T-Graphormer), a Transformer-based approach capable of modelling spatiotemporal correlations simultaneously. By adding temporal encodings in the Graphormer architecture, each node attends to all other tokens within the graph sequence, enabling the model to learn rich spacetime patterns with minimal predefined inductive biases. We show the effectiveness of T-Graphormer on real-world traffic prediction benchmark datasets. Compared to state-of-the-art methods, T-Graphormer reduces root mean squared error (RMSE) and mean absolute percentage error (MAPE) by up to 20% and 10%.
Introduction: The Challenge of Spatiotemporal Forecasting
Spatiotemporal data, such as traffic flow on a highway network, is notoriously difficult to forecast. It features non-Euclidean spatial dependencies—where two roads might be geographically close but behave differently due to network topology—and highly non-linear temporal dynamics, such as rush hour congestion.
Historically, deep learning models have tackled this by bifurcating the problem: using Graph Neural Networks (GNNs) for spatial relationships and Recurrent Neural Networks (RNNs) or 1D Convolutions for temporal trends. These models interleave layers, passing representations back and forth. However, this separation imposes a rigid information flow. T-Graphormer proposes a shift: using a single Transformer to model spatial and temporal correlations simultaneously, allowing any node at any time to directly attend to any other node at any other time.
Methodology: Unified Spatiotemporal Learning
The core innovation of T-Graphormer (Temporal-Graphormer) is the adaptation of the graph-centric Graphormer architecture for spatiotemporal time series. Instead of separate modules, T-Graphormer flattens the entire spatiotemporal graph into a single 1D sequence of tokens.
To preserve the inherent structure lost during flattening, the model employs three structural encodings:
- Centrality Encoding: Learnable embeddings based on a node's in-degree and out-degree, signaling a node's structural importance.
- Temporal Positional Encoding: Learnable embeddings that index specific time steps, preserving sequence order.
- Spatial Encoding: A learnable bias added to the attention matrix based on the Shortest Path Distance (SPD) between nodes, allowing the model to prioritize topologically closer neighbors.
A [CLS] token is prepended to the sequence to act as a global aggregator for the entire spatiotemporal window, similar to architectures like BERT or ViT.
Experimental Results
T-Graphormer was evaluated on standard traffic forecasting benchmarks, including PEMS-BAY and METR-LA. The task involved using one hour of historical data (12 five-minute intervals) to predict traffic speeds for the subsequent 15, 30, and 60 minutes.
The model achieved state-of-the-art (SOTA) performance, outperforming ten strong baselines. On the PEMS-BAY and METR-LA datasets, T-Graphormer reduced Root Mean Squared Error (RMSE) by up to 24% and Mean Absolute Percentage Error (MAPE) by up to 13% for longer-term prediction windows. For instance, on the PEMS-BAY 1-hour task, T-Graphormer achieved an RMSE of 3.20, significantly lower than the next-best baseline (STEP) at 4.20.
Ablation studies confirmed that these gains are driven by the structural encodings. Removing temporal positional encoding led to a 19% error increase, while removing centrality and spatial encodings decreased performance by 9% and 5%, respectively.
Discussion and Limitations
By allowing global attention across space and time, T-Graphormer learns complex cross-component dependencies natively. Visualizations of attention maps show the model naturally groups temporal events and focuses on spatially relevant nodes without explicit GNN message-passing constraints.
However, the model faces a significant scaling challenge. The $O(n^2)$ memory complexity of self-attention makes the model memory-intensive as the number of nodes and time steps grows. For example, the model could not be evaluated on the PEMS07 dataset due to GPU memory limits. Additionally, the current reliance on pre-computed shortest path distances assumes a static graph, limiting its application to dynamic networks with road closures or evolving structures. Future work will focus on sparse attention mechanisms and adapting the architecture for dynamic graph environments.
Summary updated