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.
Time Series Forecasting Using Foundation Models ebook for free