Overview

9 Reprogram an LLM for forecasting

This chapter introduces Time-LLM, a framework that repurposes open-source large language models for time series tasks by turning numerical signals into a form LLMs can understand. Instead of being a standalone forecasting model, Time-LLM enables multimodal inputs—historical series plus natural-language context—so practitioners can enrich predictions with domain knowledge. The approach trades the convenience of pure zero-shot use for better adaptation to time series dynamics, requiring a lightweight training phase to “reprogram” inputs and map outputs back to numeric forecasts.

Time-LLM’s pipeline normalizes and patches the series, then learns text prototypes from a small vocabulary to describe each patch (patch reprogramming), aligning numeric patterns with the LLM’s text modality. A Prompt-as-Prefix is concatenated to these reprogrammed patches to guide the model, combining contextual background, a clear task description, and input statistics (including seasonality cues extracted via fast Fourier transform). The LLM backbone remains frozen—only the reprogramming and output-projection layers are trained—so any HuggingFace LLM can be used if its hidden size is specified. This yields a flexible, multimodal forecaster, albeit currently limited to univariate inputs and dependent on compute for the training steps.

Practically, Time-LLM is available in the neuralforecast library, making it straightforward to set up prompts, choose an LLM (defaulting to GPT-2-small), and run training, prediction, and cross-validation. On a weekly retail dataset, it delivered accuracy improvements over directly prompting general-purpose LLMs, though it did not surpass the strongest time-series foundation models. The framework also supports anomaly detection by pairing cross-validation with conformal prediction intervals, but too few training steps can lead to poorly calibrated bounds and false positives. Overall, Time-LLM is most compelling when you want to inject natural-language context into forecasting and have resources to run the short reprogramming phase; otherwise, specialized time-series foundation models may remain preferable for speed or multivariate needs.

General architecture of Time-LLM. On the right, the raw series is fed to the framework and undergoes patching before entering the patch reprogramming phase. On the left, a prompt is used to give context about the data. The prompt and the reprogrammed patches are joined together as a patch embedding which is sent to the LLM. The output is then projected such that we get forecast for our series.
Illustrating patch reprogramming. Here, a subset of vocabulary is used to learn a text prototype that best describes each patch. For example, Patch 1 is described as “down steady”. Patch 2 is described as “up short”.
The prompt prefix used in Time-LLM. Elements in italics are input parameters, while values surrounded by <> are calculated. We can see three distinct elements to the prompt: context, task description and input statistics. The context gives general information about the data, the task description specifies what the LLM must do, and input statistics facilitate pattern recognition.
Comparing weekly store sales (left) to daily traffic volume (right). As we can see, series from different domains at different frequencies exhibit different patterns.
The top five lags of a dataset tracking the hourly energy consumption of a household. The plotted frequencies are 0.0051, 0.0058, 0.14, 1 and 2. To get the lag, we simply divide 24 by the frequency (since the data is hourly and have cycles per day). Thus, the top 5 lags are 4705, 4137, 168, 24, and 12. Note that the last three lags indicate a half-daily, daily and weekly seasonality.
Highlighting the training portion of Time-LLM. Here, the LLM itself is not fine-tuned. Training occurs for patch reprogramming and output projection, with thick full arrows labelling the forward pass and thick dashed arrows labelling backpropagation. Thus, we train the model to better reprogram the patches and better project the output of the LLM.
Forecasting the weekly sales of four different stores with Time-LLM. Here, the forecasts seem to be mostly flat.
Result of cross-validation with Time-LLM. The forecasts mostly overlap the actual values.
Detected anomalies by Time-LLM using cross-validation and conformal intervals. Notice that many values are falsely labelled as anomalies. This might be due to the model not being trained long enough for each window.
F1-score of all explored models in detecting anomalies of daily taxi rides. Higher is better. As you can see, Time-LLM achieves a better performance than Llama-3.2, but it is still significantly worse than Moirai and TimeGPT.

Summary

  • Time-LLM is a framework that reprograms LLMs for time series forecasting. It learns text prototypes that best describe patches of time series, thus aligning the time modality with the text modality.
  • It uses the Prompt-as-Prefix technique to add context, instructions and statistics to the input, helping the LLM perform better.
  • Since the model must be reprogrammed through training, Time-LLM cannot be used for zero-shot forecasting, since there is always some training steps to be completed.
  • Its availability in neuralforecast, which makes it easy to use and it gives us access to all functionalities available in the package.
  • Training the model for more steps is likely going to give better results, but it dramatically increases the time required to use the model.

References

FAQ

What is Time-LLM and how is it different from a foundation model?Time-LLM is a framework that reprograms existing open-source large language models (LLMs) to handle time series tasks. It is not a standalone forecasting foundation model; instead, it adapts LLMs to be multimodal, accepting both numeric time series and text context.
Why is patch reprogramming critical in Time-LLM?Patch reprogramming aligns numeric time series data with the text modality of an LLM. After normalizing and patching the series, Time-LLM learns text prototypes (from a small vocabulary) that describe each patch (e.g., “down steady”), enabling the LLM to reason over time series via natural language representations.
What is the Prompt-as-Prefix technique and what does the prompt include?Prompt-as-Prefix prepends a structured text prompt to the reprogrammed patches before sending them to the LLM. It includes: 1) context (domain/frequency info), 2) task description (e.g., forecast h steps given input size), and 3) input statistics (min/max/median, trend, and top lags found via FFT).
Does Time-LLM support zero-shot forecasting?No. Unlike models such as Chronos, Time-LLM has no pretrained weights for forecasting and always requires training for patch reprogramming and output projection. The LLM backbone remains frozen.
Which LLMs can I use and how do I set model dimensions?You can use any open-source LLM available on Hugging Face with its tokenizer and config. Time-LLM defaults to GPT-2-small. You must set d_llm to the LLM’s hidden size (e.g., 768 for GPT-2, 4096 for Llama-2-7b) so patch reprogramming and projection layers match the backbone.
How does Time-LLM produce forecasts end to end?- Normalize and patch the series, then learn text prototypes (patch reprogramming). - Build the Prompt-as-Prefix and concatenate with the patch embeddings. - Feed the combined embedding to the frozen LLM. - Flatten the LLM output and apply a linear projection back to numeric forecasts on the original scale.
What are the main limitations of Time-LLM?It is univariate (no exogenous features), has no true zero-shot capability, and always requires training time for patch reprogramming and output projection. Performance and speed depend on the chosen LLM and available compute.
How do I use Time-LLM with the neuralforecast library?Provide a prompt_prefix, instantiate TimeLLM with h, input_size, and d_llm, then wrap it in NeuralForecast with the proper freq. Call fit to train the reprogramming and projection layers, and predict or cross_validation to generate forecasts and evaluate performance.
How does anomaly detection work with Time-LLM?Use cross_validation with refit=True and PredictionIntervals to compute conformal prediction intervals at a chosen level (e.g., 99%). Flag actual values outside the interval as anomalies. Short training (few steps per window) can yield poorly calibrated intervals and more false positives.
How did Time-LLM perform in the chapter’s experiments?On weekly store sales cross-validation, Time-LLM achieved MAE ≈ 80,417 and sMAPE ≈ 2.51%, outperforming direct LLM prompting (e.g., Flan-T5, Llama-3.2) in that setup. For taxi-ride anomaly detection, it reached an F1-score ≈ 0.15, better than Llama-3.2 but worse than Moirai and TimeGPT.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Time Series Forecasting Using Foundation Models ebook for free