Gridded Transformer Neural Processes for Spatio-Temporal Data

Matthew Ashman, Cristiana Diaconu, Eric Langezaal, Adrian Weller, Richard E. TurnerICML 2025

TL;DR

Gridded Transformer Neural Processes (Gridded TNPs) bridge the gap between the flexibility of Neural Processes and the efficiency of grid-based Transformers. By projecting unstructured spatio-temporal data onto a latent grid of "pseudo-tokens," this framework scales to massive datasets (100k+ points) while maintaining superior predictive accuracy and uncertainty estimation compared to traditional convolutional baselines.

The Challenge of Spatio-Temporal Data

Modeling spatio-temporal data—such as weather patterns or fluid dynamics—is notoriously difficult. Data often originates from heterogeneous sources: some are structured on regular grids (like satellite imagery), while others are unstructured and sparse (like individual weather stations).

Neural Processes (NPs) are a powerful family of models for this domain because they can handle arbitrary input locations and provide robust uncertainty estimates. However, Transformer-based NPs (TNPs) suffer from quadratic computational complexity ($O(N^2)$) relative to the number of data points. This makes them prohibitively expensive for large-scale real-world applications. Conversely, efficient "foundation" models for weather (like Pangu-Weather or GraphCast) are often locked into fixed-resolution grids and struggle to incorporate unstructured observations.

The authors aim to create a model that offers the best of both worlds: the flexibility of an NP and the efficiency of a grid-based Transformer.

The Gridded TNP Pipeline

The core innovation of this paper is a three-part processor pipeline that "grids" the problem to leverage efficient attention mechanisms:

  1. Pseudo-Token Grid Encoder: Instead of relying on simple mathematical interpolation, the model uses a novel attention-based encoder. It cross-attends unstructured context observations to a fixed grid of "pseudo-tokens." This allows the model to capture complex, localized topographical information (like elevation) at each grid location.
  2. Efficient Grid Processor: Once the data is structured on a grid, the model utilizes state-of-the-art architectures like the Vision Transformer (ViT) or Swin Transformer. The Swin Transformer is particularly effective here, as its shifted-window attention scales linearly with the number of grid points.
  3. Nearest-Neighbor Grid Decoder: To make predictions at arbitrary target locations, the authors employ a $k$-nearest-neighbor cross-attention mechanism. Instead of attending to the entire grid, target points only look at the $k$ closest pseudo-tokens, drastically reducing computational costs.
The complete Gridded TNP pipeline: Encoding unstructured data to a grid, processing with a Transformer, and decoding to target locations.

The authors also introduce Translation Equivariance (TE) into the architecture. By using learnable relative positional encodings in the Swin blocks, the model learns that a pattern shifted in space or time should be treated similarly—a powerful inductive bias for physical data.

Experimental Datasets

The model was evaluated on a diverse set of challenges to test its versatility:

  • Synthetic 2D Gaussian Processes: Testing the ability to recover complex, high-frequency "wiggles" in spatial data.
  • ERA5 Weather Reanalysis:
  • Station Prediction: Combining structured skin temperature data with unstructured 2-meter temperature observations from roughly 10,000 weather stations.
  • Multi-modal Wind Speed: Modeling $u$ and $v$ wind components across three different atmospheric pressure levels.
  • EAGLE Fluid Dynamics: A large-scale dataset of 2D drone airflow simulations on irregular meshes, testing the model's ability to act as a neural partial differential equation (PDE) solver.

Key Insights

  • Grid Encoding > Kernel Interpolation: The pseudo-token encoder consistently outperforms the simple kernel-based interpolation used in prior models like ConvCNP. It allows the network to learn how to aggregate local information rather than relying on a fixed mathematical kernel.
  • The Locality Bonus: Surprisingly, the nearest-neighbor decoder doesn't just save time—it often improves accuracy. This suggests that for spatio-temporal data, local information is a more reliable predictor than distant global context, providing a "beneficial inductive bias."
  • Approximate Equivariance is King: While strict translation equivariance helps, real-world data is rarely perfectly symmetric. The authors found that "approximate" equivariance (allowing the model to learn some symmetry-breaking features) provided the best balance of generalization and flexibility.

Key Results

Gridded TNPs—specifically the Swin-TNP variant—consistently outperformed strong baselines like ConvCNP and standard PT-TNPs across all tasks.

  • Gaussian Process Tasks: On complex datasets, Swin-TNP achieved significantly higher log-likelihoods than ConvCNP while maintaining competitive processing speeds.
Performance vs. Speed: Swin-TNP variants (stars) occupy the top-left, demonstrating superior accuracy and speed compared to baselines.
  • Weather Modeling: In the weather station experiment, Swin-TNP achieved a test log-likelihood of 1.819, compared to 1.535 for ConvCNP and 1.344 for standard PT-TNPs.
  • Scalability: The model successfully handled context sets with over 100,000 datapoints, a regime where standard Transformer NPs would run out of memory.

Limitations and Future Work

  • Hyperparameter Sensitivity: The choice of grid resolution ($M$) is a critical hyperparameter. While larger grids generally perform better, they proportionally increase memory and compute costs.
  • Forecasting vs. Estimation: This paper focuses primarily on state estimation and spatial interpolation. Extending this framework to true autoregressive spatio-temporal forecasting is a logical next step.
  • Memory Bottlenecks: Even with efficient attention, the number of pseudo-tokens is still limited by GPU memory, which might constrain applications requiring extremely high-resolution global grids.

Summary updated

BibTeX
@inproceedings{ashman2025gridded,
  author = {Matthew Ashman and Cristiana Diaconu and Eric Langezaal and Adrian Weller and Richard E. Turner},
  title = {{Gridded Transformer Neural Processes for Spatio-Temporal Data}},
  booktitle = {International Conference on Machine Learning},
  year = {2025},
  url = {https://openreview.net/forum?id=O0oe7hPtbl},
}
Figure