Spatial-Temporal Large Language Model for Traffic Prediction

Chenxi Liu, Sun Yang, Qianxiong Xu, Zhishuai Li, Cheng Long, Ziyue Li, Rui Zhao

Abstract

Traffic prediction is a cornerstone of intelligent transportation systems, yet traditional Graph Neural Networks (GNNs) often struggle with global dependencies and the "over-smoothing" of spatial data. This paper introduces ST-LLM (Spatial-Temporal Large Language Model), a framework that repurposes pre-trained Large Language Models (LLMs) like GPT-2 for spatial-temporal forecasting. By treating spatial locations as tokens and employing a novel "Partially Frozen Attention" (PFA) strategy, ST-LLM effectively captures complex urban dynamics. Experiments on large-scale taxi and bike-sharing datasets demonstrate that ST-LLM significantly outperforms state-of-the-art models and exhibits robust zero-shot transfer capabilities across different urban environments.

Introduction

Accurate traffic forecasting—predicting flow and demand—is essential for urban planning and congestion management. While Graph Convolutional Networks (GCNs) have been the standard for modeling non-Euclidean spatial structures, their accuracy has plateaued. These models often struggle to capture global patterns due to the localized nature of graph convolutions. Simultaneously, while LLMs have shown superb performance in general time-series analysis, they typically focus on the temporal dimension and ignore the critical spatial correlations inherent in traffic data, such as how a traffic jam in one neighborhood propagates to another.

ST-LLM bridges this gap by adapting the GPT-2 architecture to handle spatial-temporal sequences, treating the entire city's traffic state as a coherent "sentence" where locations serve as the individual words.

Methodology

ST-LLM's architecture centers on three main innovations designed to bridge the gap between natural language processing and traffic science:

1. Spatial-Temporal Tokenization

Instead of traditional time-step tokenization, ST-LLM defines timesteps at specific locations as tokens. This allows the model's attention mechanism to naturally solve the over-smoothing problem found in GCNs, providing a truly global view of the traffic network.

2. ST-Embedding and Fusion

To help the LLM interpret non-textual data, the authors designed a specialized embedding layer that encodes three distinct information streams:

  • Raw Traffic Values: The actual flow or demand metrics.
  • Temporal Metadata: Temporal context such as hour-of-day and day-of-week.
  • Adaptive Spatial Embedding: A learnable component that identifies relationships between different locations without requiring a pre-defined adjacency matrix.

3. Partially Frozen Attention (PFA)

This is the core architectural contribution. Rather than fine-tuning the entire LLM—which is computationally expensive and risks "forgetting" pre-trained knowledge—the authors propose:

  • Freezing the first $F$ layers to preserve foundational structural knowledge.
  • In the remaining $U$ layers, unfreezing only the Multi-Head Attention (MHA) while keeping the Feed-Forward Networks (FFN) frozen.

This strategy allows the model to learn new spatial-temporal relationships while leveraging the LLM's inherent reasoning structure. Research indicates that unfreezing only 1 or 2 attention layers is the "sweet spot"; unfreezing more can actually degrade performance by disrupting the LLM's structural priors.

Experimental Setup

The model was validated using two large-scale, real-world datasets from 2016:

  • NYCTaxi: 35 million taxi trips in New York City, categorized into 266 virtual stations.
  • CHBike: 2.6 million Citi Bike orders in Chicago, focused on the 250 most frequent stations.

Both datasets were processed at 30-minute intervals and split 6:2:2 for training, validation, and testing.

Key Results and Discussion

ST-LLM outperformed 10 major baselines, including specialized traffic models like DCRNN, GWN, and GMAN. Key findings include:

  • Superior Accuracy: The model achieved a 22.5% average MAE improvement over OFA (a leading LLM-based time-series model) and a 20.8% improvement over Llama-2-based approaches.
  • Zero-Shot Transferability: ST-LLM demonstrated remarkable knowledge transfer. A model trained only on NYC Taxi data could predict Chicago Bike flow with higher accuracy than many models trained specifically on that Chicago data. This suggests the LLM learns a universal "spatial-temporal logic."
  • Few-Shot Robustness: With only 10% of the training data, ST-LLM still outperformed most full-data baselines, highlighting the efficiency of the pre-trained backbone.
  • Computational Efficiency: Despite its LLM foundation, ST-LLM maintains competitive inference times. It is significantly faster than other LLM-based traffic models like GATGPT because its PFA strategy avoids adding heavy computational overhead to the backbone.

Conclusion and Future Work

ST-LLM represents a significant advancement in applying LLMs to spatial-temporal tasks by successfully integrating spatial awareness into the attention mechanism. While the current study focuses on traffic flow, the authors suggest that future work should explore multi-task learning—such as simultaneous traffic imputation and anomaly detection. Additionally, addressing the quadratic complexity of attention will be necessary to scale the model to networks involving tens of thousands of sensors.

Summary updated

BibTeX
@inproceedings{liu2024spatial,
  author = {Chenxi Liu and Sun Yang and Qianxiong Xu and Zhishuai Li and Cheng Long and Ziyue Li and Rui Zhao},
  title = {{Spatial-Temporal Large Language Model for Traffic Prediction}},
  booktitle = {MDM},
  year = {2024},
}
Figure