许可协议:apache-2.0
任务类型:时间序列预测
标签:
- 时间序列
- 预测
- 预训练模型
- 基础模型
- 时间序列基础模型
- 时序分析
Chronos-T5(小规模版)
🚀 2025年2月14日更新:Chronos-Bolt及原版Chronos模型现已登陆Amazon SageMaker JumpStart!查看教程笔记本,学习如何用几行代码部署Chronos端点用于生产环境。
🚀 2024年11月27日更新:我们发布了Chronos-Bolt⚡️系列模型,相比同尺寸原版Chronos模型,其误差降低5%,速度提升250倍,内存效率提高20倍。访问新模型库了解更多。
Chronos是基于语言模型架构的预训练时间序列预测模型家族。通过量化和缩放将时间序列转化为标记序列,语言模型使用交叉熵损失在这些标记上进行训练。训练完成后,通过给定历史上下文采样多条未来轨迹来获得概率预测。Chronos模型已在大量公开时间序列数据及高斯过程生成的合成数据上进行训练。
关于模型细节、训练数据与流程及实验结果,请参阅论文《Chronos:学习时间序列的语言》。
图1:Chronos核心流程示意图。(左)输入时间序列经缩放量化转为标记序列。(中)标记输入语言模型(编码器-解码器或纯解码架构),模型通过交叉熵损失训练。(右)推理时自回归采样标记并映射回数值,通过多次采样轨迹获得预测分布。
架构
本仓库模型基于T5架构,唯一区别在于词汇量:Chronos-T5采用4096个标记(原版T5为32128个),参数量更少。
使用指南
安装配套代码库以运行Chronos模型推理:
pip install git+https://github.com/amazon-science/chronos-forecasting.git
基础推理示例:
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-small",
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="历史数据")
plt.plot(forecast_index, median, color="tomato", label="预测中位数")
plt.fill_between(forecast_index, low, high, color="tomato", alpha=0.3, label="80%置信区间")
plt.legend()
plt.grid()
plt.show()
引用
若使用Chronos模型,请引用论文:
@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}
}
安全声明
详见贡献指南中的安全说明。
许可证
本项目采用Apache-2.0许可证。