PLMTrajRec: A Scalable and Generalizable Trajectory Recovery Method with Pre-trained Language Models

Tonglong Wei, Yan Lin, Youfang Lin, Shengnan Guo, Jilin Hu, Haitao Yuan, Gao Cong, Huaiyu Wan

TL;DR

Reconstructing dense, map-matched vehicle trajectories from sparse GPS data is notoriously difficult due to data scarcity and varying sampling rates. PLMTrajRec solves this by adapting pre-trained language models (PLMs) to spatiotemporal data using parameter-efficient fine-tuning, explicit natural language prompts, and a novel road-condition passing mechanism. It achieves state-of-the-art recovery accuracy even with highly limited training data.

What Problem Does This Paper Address?

GPS tracking data is crucial for urban planning and traffic management, but it is frequently sparse due to network instability, device malfunctions, or battery-saving settings. Map-matched trajectory recovery aims to fill in these missing points directly onto a road network.

However, existing deep learning models face three major hurdles:

  1. Data Scarcity: They require massive amounts of dense trajectory data to train from scratch, which is rarely available in real-world scenarios.
  2. Varying Sampling Intervals: Models struggle to generalize across different or unseen sampling intervals (e.g., a model trained on 1-minute intervals often fails when deployed on 4-minute intervals).
  3. Unknown Environmental Context: Incorporating dynamic road conditions (like traffic congestion) is incredibly hard for missing points because their exact locations are unknown, yet traffic heavily dictates route choices.
Figure 1: Impact of road conditions on route selection and movement patterns.

Methods

The authors introduce PLMTrajRec, a framework that repurposes a pre-trained BERT model for trajectory recovery. Instead of treating trajectories purely as coordinate sequences, the model translates the problem into a sequence-completion task that a language model can understand.

The pipeline consists of three main stages:

  1. Dual Trajectory Prompts: To provide context, the model uses an Interval and Feature-guided (IF-guided) explicit prompt (natural language text describing the sampling rate, trip duration, and distance) and an Area Flow-guided (AF-guided) implicit prompt (capturing regional traffic patterns via 2D/1D CNNs).
  2. Interval-aware Trajectory Embedder: This module standardizes varying sparse intervals into a unified target interval by inserting a placeholder [m] for missing points. Observed points are encoded using Learnable Fourier Features (LFF) and road network embeddings. For missing points, a Road Condition Passing Mechanism estimates traffic conditions by interpolating from the nearest forward and backward observed points using a time-decay factor.
  3. PLM-based Trajectory Encoder: A pre-trained BERT model is frozen except for its attention layers, which are fine-tuned using Low-Rank Adaptation (LoRA). This allows the model to leverage its inherent sequence-modeling capabilities to capture bidirectional spatiotemporal relationships and predict the correct road segment and moving ratio for every point.
Figure 3: The framework of PLMTrajRec, consists of Dual Trajectory Prompts, Interval-aware Trajectory Embedder, and PLM-based Trajectory Encoder.

Datasets

The model was evaluated on two large-scale, real-world taxi trajectory datasets:

  • Chengdu Dataset: Trajectory data from Chengdu, China (November 2016), containing 118,354 trajectories over a road network of 2,504 segments.
  • Porto Dataset: Trajectory data from 442 taxis in Porto, Portugal (July 2013 – June 2014), containing 322,079 trajectories over 2,224 road segments.

Both datasets were standardized to a dense 15-second ground truth interval and downsampled to 1-minute, 2-minute, and 4-minute intervals to simulate sparse data.

Table 1: Dataset Description.

Key Insights and Ideas

  • LLMs as Spatiotemporal Engines: Instead of training complex spatial-temporal networks from scratch, freezing a pre-trained language model and fine-tuning it with LoRA provides an incredibly strong inductive bias for sequence reconstruction.
  • Prompting with Numbers and Text: Converting abstract sampling rates into natural language prompts (e.g., "The sparse trajectory is sampled every four minutes...") allows the PLM to dynamically adjust its internal attention mechanisms to handle different temporal gaps.
  • Message Passing for Traffic: Since the exact location of a missing point is unknown, traffic conditions can be effectively "passed" down from known endpoints. The time-decayed interpolation perfectly mirrors how traffic congestion propagates over short intervals.

Key Results

  • State-of-the-Art Performance: PLMTrajRec consistently outperformed 12 baseline models (including specialized trajectory models like RNTrajRec and MM-STGED) across all sampling intervals.
  • Massive Error Reduction: On the challenging 4-minute interval task, PLMTrajRec reduced the coordinate recovery error (RMSE) by an average of 351.8 meters in Chengdu and 119.2 meters in Porto compared to the best baselines.
  • High Data Efficiency (Scalability): When trained on just 20% of the dense trajectory data, PLMTrajRec still outperformed almost all baselines trained on 100% of the data, demonstrating its exceptional data efficiency.
  • Zero-Shot Generalization: When trained only on 1-minute and 4-minute intervals and tested on an unseen 2-minute interval, PLMTrajRec maintained high accuracy with minimal performance drop, whereas baseline models collapsed.
Table 2: Performance comparison on two datasets with sampling intervals at 4 minutes, 2 minutes, and 1 minute, respectively. The best results are highlighted in bold, while the underline indicates the second-best results.

Limitations and Future Work

  • Model Size and Footprint: Because it relies on a pre-trained language model framework, PLMTrajRec has a larger model size (around 175 MB) compared to smaller end-to-end deep learning baselines, though its parallel inference strategy makes it faster during execution.
  • Grid-Based Traffic Simplification: The road condition prompt relies on a fixed spatial grid (64x64) to calculate traffic flows, which might lose fine-grained road-level traffic dynamics.
  • Future Directions: The authors suggest exploring even larger foundation models or extending the framework to handle multimodal trajectory data (e.g., combining GPS with cellular signaling data).

Summary updated

Abstract

Spatiotemporal trajectory data is crucial for various applications. However, issues such as device malfunctions and network instability often cause sparse trajectories, leading to lost detailed movement information. Recovering the missing points in sparse trajectories to restore the detailed information is thus essential. Despite recent progress, several challenges remain. First, the lack of large-scale dense trajectory data makes it difficult to train a trajectory recovery model from scratch. Second, the varying spatiotemporal correlations in sparse trajectories make it hard to generalize recovery across different sampling intervals. Third, the lack of location information complicates the extraction of road conditions for missing points. To address these challenges, we propose a novel trajectory recovery model called PLMTrajRec. It leverages the scalability of a pre-trained language model (PLM) and can be fine-tuned with only a limited set of dense trajectories. To handle different sampling intervals in sparse trajectories, we first convert each trajectory's sampling interval and movement features into natural language representations, allowing the PLM to recognize its interval. We then introduce a trajectory encoder to unify trajectories of varying intervals into a single interval and capture their spatiotemporal relationships. To obtain road conditions for missing points, we propose an area flow-guided implicit trajectory prompt, which models road conditions by collecting traffic flows in each region. We also introduce a road condition passing mechanism that uses observed points' road conditions to infer those of the missing points. Experiments on two public trajectory datasets with three sampling intervals each demonstrate the effectiveness, scalability, and generalization ability of PLMTrajRec.
BibTeX
@inproceedings{wei2025plmtrajrec,
  author = {Tonglong Wei and Yan Lin and Youfang Lin and Shengnan Guo and Jilin Hu and Haitao Yuan and Gao Cong and Huaiyu Wan},
  title = {{PLMTrajRec: A Scalable and Generalizable Trajectory Recovery Method with Pre-trained Language Models}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=SJPq1xBPHX},
}
Figure