TL;DR
TrajTok introduces a general-purpose trajectory foundation model that processes raw, noisy GPS data using a density-adaptive, multi-resolution hexagonal tokenization scheme. By decoupling and later fusing geometric (location) and kinematic (motion) features through a factorized transformer architecture, a single frozen TrajTok encoder achieves state-of-the-art performance across diverse downstream tasks ranging from trajectory similarity search to travel-time estimation.
What Problem Does This Paper Address?
Analyzing human mobility from raw GPS traces is notoriously difficult. The data is continuous, noisy, and irregularly sampled. To process these sequences with modern transformer architectures, researchers typically discretize space into fixed-size grids (like standard Geohashes or fixed-resolution grids).
However, fixed grids introduce a tough tradeoff:
- Fine-resolution grids preserve local details but suffer from data sparsity, creating cells with too few GPS visits to learn robust embeddings.
- Coarse-resolution grids provide strong statistical support but suffer from internal fragmentation, merging completely different local movement patterns into the same token.
Furthermore, most existing trajectory models are highly specialized—optimized either for geometry-dominated tasks (e.g., finding similar routes) or kinematics-dominated tasks (e.g., predicting travel times). The authors tackle the challenge of building a unified, generalizable trajectory encoder that handles both aspects without relying on expensive map-matching preprocessing.
Methods
TrajTok introduces three core design innovations to build a robust trajectory foundation model:
- Adaptive Spatial Tokenization: Instead of a uniform grid, TrajTok constructs a multi-resolution vocabulary using hierarchical H3 hexagonal cells. Starting from a base resolution, cells that exceed a specific data-point capacity threshold are recursively split into finer children. This ensures that high-density urban centers get fine-grained tokens, while sparse rural areas use coarser tokens, maintaining a compact and statistically stable vocabulary.
- Factorized Transformer Encoder: The architecture splits trajectory features into two independent channels early on:
- Geometric Channel: Encodes discrete cell IDs and spatial positions.
- Kinematic Channel: Encodes continuous motion features (normalized speed and heading represented via sine/cosine to respect circularity).
Each channel processes its features using self-attention blocks equipped with Spatiotemporal Rotary Position Embeddings (ST-RoPE) before merging them via cross-attention fusion layers.
- Run-Aware Masked Pretraining: TrajTok is pretrained using a co-masked objective where the geometric channel predicts masked cell IDs and the kinematic channel regresses speed and heading. To prevent the model from exploiting "shortcuts"—such as trivially copying adjacent tokens when a vehicle is stationary or moving through a massive coarse cell—the authors introduce run-aware span masking, which rejects mask candidates that fall entirely within a single repeated-cell run.
Datasets
The model is trained and evaluated on the widely used Porto taxi dataset, which contains 1,710,670 trajectories from taxi trips in Porto, Portugal. The authors split the dataset using a deterministic 60/20/20 hash-based split for training, validation, and testing.
Key Insights and Ideas
- Density-Adaptive Discretization is Essential: Uniform grids inherently fail to model non-uniform human mobility. Allocating spatial resolution based on empirical data density balances token precision and statistical support perfectly.
- Early Factorization Prevents Task Shortcuts: Decoupling where an agent goes from how it moves allows the transformer streams to specialize. Cross-attention fusion ensures that the final representation captures the interplay between route and pace, which is vital for complex tasks like travel-time estimation.
- The Pretraining-Transfer Mismatch: Interestingly, the authors observed that continuing pretraining to minimize masked-token validation loss past a certain point (e.g., from 60k to 120k steps) actually degraded downstream zero-shot retrieval performance. This reveals that lower pretext loss does not automatically guarantee a more transferable trajectory representation.
Key Results
A single frozen TrajTok encoder equipped with lightweight task-specific adapters matched or outperformed specialized, state-of-the-art baselines across four distinct benchmarks:
- Trajectory Similarity Search: Reached a Hit Ratio (HR@1) of 0.435, significantly outperforming strong baselines like NeuTraj (0.308) and SIMformer (0.300).
- Estimated Time of Arrival (ETA) from Prefixes: Achieved a Mean Absolute Error (MAE) of 42.27 seconds, cutting the error of the previous best model (MetaER-TTE at 93.75 s) more than in half.
- Full-Trajectory Travel-Time Regression: Achieved an MAE of 38.41 seconds, outperforming the specialized TIGR model (86.86 s).
- Trajectory Classification (Call-Type): Reached a macro-F1 score of 0.773, performing on par with models like START (0.772) that explicitly rely on external, map-matched road network graphs.
Limitations and Future Work
- Single-City Evaluation: All experiments were conducted purely on the Porto taxi dataset. The authors note that evaluating cross-city transfer learning and scaling pretraining to diverse global cities remains an open next step.
- Lack of Explicit Geographic Priors: TrajTok operates purely on raw GPS traces. While this eliminates heavy preprocessing pipelines, enriching the spatial tokens with lightweight geographic features (such as points of interest or basic road network topologies) directly at the token level could further improve performance.
Summary updated