🚀 2025年2月14日更新:Chronos-Bolt 和原始 Chronos 模型现已在 Amazon SageMaker JumpStart 上线!查看 教程笔记本,了解如何通过几行代码部署 Chronos 端点以用于生产环境。
🚀 2024年11月27日更新:我们发布了 Chronos-Bolt⚡️ 模型,与相同规模的原始 Chronos 模型相比,其准确率更高(误差降低5%),速度快达250倍,内存效率提升20倍。此处查看新模型。
Chronos 是一系列基于语言模型架构的预训练时间序列预测模型。时间序列通过缩放和量化转换为标记序列,语言模型使用交叉熵损失对这些标记进行训练。训练完成后,通过给定历史上下文采样多个未来轨迹,即可获得概率预测。Chronos 模型已在大量公开可用的时间序列数据以及使用高斯过程生成的合成数据上进行了训练。
有关 Chronos 模型、训练数据和流程以及实验结果的详细信息,请参阅论文 Chronos: Learning the Language of Time Series。
图1:Chronos 的高层级描述。(左)对输入时间序列进行缩放和量化,以获得标记序列。(中)将标记输入到语言模型中,该模型可以是编码器-解码器模型或仅解码器模型。使用交叉熵损失对模型进行训练。(右)推理期间,我们从模型中自回归采样标记,并将其映射回数值。通过采样多个轨迹来获得预测分布。
本仓库中的模型基于 T5 架构。唯一的区别在于词汇表大小:Chronos-T5 模型使用 4096 个不同的标记,而原始 T5 模型使用 32128 个,因此参数数量更少。
| 模型 | 参数数量 | 基于 |
|---|---|---|
| chronos-t5-tiny | 800 万 | t5-efficient-tiny |
| chronos-t5-mini | 2000 万 | t5-efficient-mini |
| chronos-t5-small | 4600 万 | t5-efficient-small |
| chronos-t5-base | 2 亿 | t5-efficient-base |
| chronos-t5-large | 7.1 亿 | t5-efficient-large |
要使用 Chronos 模型进行推理,请通过运行以下命令安装 GitHub 配套仓库 中的软件包:
pip install git+https://github.com/amazon-science/chronos-forecasting.git一个展示如何使用 Chronos 模型执行推理的简单示例:
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 must be either a 1D tensor, a list of 1D tensors,
# or a left-padded 2D tensor with batch as the first dimension
context = torch.tensor(df["#Passengers"])
prediction_length = 12
forecast = pipeline.predict(context, prediction_length) # shape [num_series, num_samples, prediction_length]
# visualize the forecast
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()如果您发现Chronos模型对您的研究有所帮助,请考虑引用相关的论文:
@article{ansari2024chronos,
title={Chronos: Learning the Language of Time Series},
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},
journal={Transactions on Machine Learning Research},
issn={2835-8856},
year={2024},
url={https://openreview.net/forum?id=gerNCVqqtR}
}有关更多信息,请参阅 贡献指南。
本项目采用 Apache-2.0 许可证。