đ Chronos-T5 (Large)
Chronos is a collection of pretrained time series forecasting models built on language model architectures. It transforms time series into token sequences through scaling and quantization, then trains a language model on these tokens using cross - entropy loss. After training, probabilistic forecasts are generated by sampling multiple future trajectories based on historical context. Chronos models are trained on a large corpus of publicly available time series data and synthetic data generated by Gaussian processes.
For detailed information about Chronos models, training data, procedures, and experimental results, please refer to the paper Chronos: Learning the Language of Time Series.
Fig. 1: High - level depiction of Chronos. (Left) The input time series is scaled and quantized to obtain a sequence of tokens. (Center) The tokens are fed into a language model which may either be an encoder - decoder or a decoder - only model. The model is trained using the cross - entropy loss. (Right) During inference, we autoregressively sample tokens from the model and map them back to numerical values. Multiple trajectories are sampled to obtain a predictive distribution.
đ Quick Start
To start using Chronos models, you need to install the relevant package. Run the following command:
pip install git+https://github.com/amazon-science/chronos-forecasting.git
⨠Features
Chronos is a family of pretrained time series forecasting models. It leverages language model architectures, transforming time series into token sequences for training. After training, it can generate probabilistic forecasts by sampling future trajectories.
đĻ Installation
To install the necessary package for Chronos models, run the following command:
pip install git+https://github.com/amazon-science/chronos-forecasting.git
đģ Usage Examples
Basic Usage
Here is a minimal example showing how to perform inference using Chronos models:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import torch
from chronos import ChronosPipeline
pipeline = ChronosPipeline.from_pretrained(
"amazon/chronos-t5-large",
device_map="cuda",
torch_dtype=torch.bfloat16,
)
df = pd.read_csv("https://raw.githubusercontent.com/AileenNielsen/TimeSeriesAnalysisWithPython/master/data/AirPassengers.csv")
context = torch.tensor(df["#Passengers"])
prediction_length = 12
forecast = pipeline.predict(context, prediction_length)
forecast_index = range(len(df), len(df) + prediction_length)
low, median, high = np.quantile(forecast[0].numpy(), [0.1, 0.5, 0.9], axis=0)
plt.figure(figsize=(8, 4))
plt.plot(df["#Passengers"], color="royalblue", label="historical data")
plt.plot(forecast_index, median, color="tomato", label="median forecast")
plt.fill_between(forecast_index, low, high, color="tomato", alpha=0.3, label="80% prediction interval")
plt.legend()
plt.grid()
plt.show()
đ Documentation
Architecture
The models in this repository are based on the T5 architecture. The main difference lies in the vocabulary size: Chronos - T5 models use 4096 different tokens, while the original T5 models use 32128, resulting in fewer parameters.
Model |
Parameters |
Based on |
chronos-t5-tiny |
8M |
[t5 - efficient - tiny](https://huggingface.co/google/t5 - efficient - tiny) |
chronos-t5-mini |
20M |
[t5 - efficient - mini](https://huggingface.co/google/t5 - efficient - mini) |
chronos-t5-small |
46M |
[t5 - efficient - small](https://huggingface.co/google/t5 - efficient - small) |
chronos-t5-base |
200M |
[t5 - efficient - base](https://huggingface.co/google/t5 - efficient - base) |
chronos-t5-large |
710M |
[t5 - efficient - large](https://huggingface.co/google/t5 - efficient - large) |
đ License
This project is licensed under the Apache - 2.0 License.
đ Citation
If you find Chronos models useful for your research, please consider citing the associated paper:
@article{ansari2024chronos,
author = {Ansari, Abdul Fatir and Stella, Lorenzo and Turkmen, Caner and Zhang, Xiyuan, and Mercado, Pedro and Shen, Huibin and Shchur, Oleksandr and Rangapuram, Syama Syndar and Pineda Arango, Sebastian and Kapoor, Shubham and Zschiegner, Jasper and Maddix, Danielle C. and Mahoney, Michael W. and Torkkola, Kari and Gordon Wilson, Andrew and Bohlke - Schneider, Michael and Wang, Yuyang},
title = {Chronos: Learning the Language of Time Series},
journal = {arXiv preprint arXiv:2403.07815},
year = {2024}
}
đ Security
See [CONTRIBUTING](CONTRIBUTING.md#security - issue - notifications) for more information.