chronos-t5-mini / README.md
lostella's picture
add example, fix table
d93a81f
|
raw
history blame
3.22 kB
metadata
license: apache-2.0
tags:
  - time series
  - forecasting
  - pretrained models
  - foundation models
  - time series foundation models
  - time-series

Chronos-T5 Mini

Chronos models are pre-trained time series forecasting models based on language model architectures. A time series is transformed into a sequence of tokens via scaling and quantization, and forecasts are obtained by sampling multiple sequences of future observations given historical context. Chronos models are trained on a large corpus of publicly available time series data, as well as synthetic data.

For details on Chronos models, training data and procedures, and experimental results, refer to the paper Chronos: Learning the Language of Time Series.

Architecture

The model in this repository is based on the T5 architecture. The only difference is in the vocabulary size: Chronos-T5 uses 4096 different tokens, compared to 32128 of the original T5 models, resulting in a smaller number of total parameters.

Usage

To do inference with Chronos models, you will need to install the code from the companion GitHub repo.

pip install git+https://github.com/amazon-science/chronos-forecasting.git

A minimal example:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import torch
from chronos import ChronosPipeline

pipeline = ChronosPipeline.from_pretrained("amazon/chronos-t5-base")

df = pd.read_csv(
    "https://raw.githubusercontent.com/AileenNielsen/"
    "TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv",
    index_col=0,
    parse_dates=True,
)

context = torch.Tensor(df["#Passengers"].values)
forecast = pipeline.predict(context, prediction_length=12)

forecast_steps = range(len(df), len(df) + 12)
forecast_np = forecast.numpy()[0].T
low = np.quantile(forecast_np, 0.1, axis=1)
median = np.quantile(forecast_np, 0.5, axis=1)
high = np.quantile(forecast_np, 0.9, axis=1)

plt.plot(range(len(df)), df["#Passengers"], color="royalblue", label="historical data")
plt.plot(forecast_steps, forecast_np, color="grey", alpha=0.1)
plt.fill_between(forecast_steps, low, high, color="tomato", alpha=0.4, label="80% interval")
plt.plot(forecast_steps, median, color="tomato", label="median")
plt.legend()
plt.grid()
plt.show()

References

If you find Chronos models useful for your research, please consider citing the associated paper:

paper citation