In-context Time Series Predictor

Jiecheng Lu, Yan Sun, Shihao Yang

Introduction

The In-context Time Series Predictor (ICTSP) reimagines time series forecasting (TSF) by treating "forecasting tasks" themselves as tokens. By providing a sequence of (lookback, future) pairs within a single prompt, the model leverages the in-context learning (ICL) power of Transformers to achieve state-of-the-art results in zero-shot and few-shot scenarios—all without needing the massive parameter counts of pre-trained Large Language Models (LLMs).

The Challenges in Time Series Forecasting

Time series forecasting has recently seen a tug-of-war between complex Transformer models and surprisingly effective simple linear predictors. Existing Transformer-based TSF models often fall into two architectural traps:

  1. Temporal-wise Transformers: These models treat each timestep as a token. They often overfit to noisy channel correlations and suffer from "timestep mixing," where the model inadvertently ignores the inherent chronological order of time.
  2. Series-wise Transformers: These treat an entire series as a single token. While better at capturing temporal patterns, they lack the ability to learn from context examples provided in a prompt—a hallmark capability of modern LLMs.
Comparison of Transformer architectures for time series

While some researchers have tried to "reprogram" massive pre-trained LLMs for time series, these methods are computationally expensive and do not always align with the underlying structure of the data. ICTSP asks a fundamental question: Can we build a parameter-efficient Transformer that inherently understands how to learn from context for time series?

Methodology: Task-as-Token and In-Context Prompting

The core innovation of ICTSP is its architecture, which reformulates the input. Instead of feeding the model raw numerical values, the authors construct tokens that represent complete forecasting tasks.

Analogy between standard In-context Learning and ICTSP
  • Task-as-Token: Each input token is a pair consisting of a "lookback" window (historical data) and its corresponding "future" window (the ground truth).
  • In-Context Prompting: A prompt is built by concatenating several of these "context example" tokens, followed by a "target" token. The target token contains a lookback window but leaves a placeholder for the future window it needs to predict.
  • Token Retrieval (TR): To handle long histories without exponentially increasing computational costs, the model uses a similarity-based retrieval mechanism. It calculates the cosine similarity between the target token and potential context tokens in a latent space, selecting only the most relevant examples to attend to.
  • Adaptive Model Reduction: The architecture is highly flexible. If the data is extremely noisy or lacks clear patterns, ICTSP can mathematically "degrade" into a simpler linear predictor or a univariate MLP. This prevents the overfitting that typically plagues more rigid Transformer architectures.

Key Insights and Performance

The authors evaluated ICTSP on a battery of standard TSF benchmarks, including ETT (Electricity Transformer Temperature), Electricity (ECL), Traffic, Weather, and a synthetic Multi Dataset designed to test complex inter-series dependencies.

Aligning with ICL Mechanics

By using (lookback, future) pairs, the model isn't just learning a static mapping; it is learning how to forecast based on the examples it sees in the current window. This perfectly mimics how LLMs solve new tasks via few-shot prompting. Furthermore, because each token is a self-contained task, swapping the order of context examples doesn't break the temporal logic, solving the permutation invariance issue common in standard Transformers.

Efficiency over Scale

Unlike models like "Time-LLM" or "GPT4TS," which rely on billions of parameters, ICTSP achieves superior performance with only ~7.4M parameters. It proves that structural alignment and proper tokenization can outweigh raw model size. Using Token Retrieval, ICTSP reduced FLOPs from ~88G to just 1.51G for certain forecasting horizons, making it highly practical for real-world deployment.

State-of-the-Art Results

ICTSP consistently outperformed a wide array of baselines, including iTransformer, PatchTST, and LLM-based methods:

  • Full-Data Setting: ICTSP achieved the best performance in nearly all categories, boasting an Average Rank of 1.36 (surpassing the next best, Time-LLM, at 1.93).
  • Few-Shot (10% Data): On the ETTh1 dataset, ICTSP achieved an MSE of 0.525, significantly beating PatchTST (0.633).
  • Zero-Shot Transfer: When trained on one ETT dataset and tested on another, ICTSP surpassed all previous methods by a large margin, proving its robust ability to adapt to new patterns on the fly.

Limitations and Future Directions

While the results are highly promising, the authors note a few areas for future growth. First, the model has not yet been tested with massive layer counts or on "foundation-scale" collective datasets, primarily because such large-scale time series repositories are still scarce. Second, the model is currently trained per dataset; future work could explore a single "Global ICTSP" capable of handling any lookback or future length across diverse domains. Finally, in few-shot settings, the very first few predictions lack prior context tokens, which can temporarily dampen performance until more data is processed.

Summary updated

BibTeX
@inproceedings{lu2025context,
  author = {Jiecheng Lu and Yan Sun and Shihao Yang},
  title = {{In-context Time Series Predictor}},
  booktitle = {International Conference on Learning Representations},
  year = {2025},
  url = {https://openreview.net/forum?id=dCcY2pyNIO},
}
Figure