许可协议: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是基于语言模型架构的预训练时间序列预测模型家族。通过量化和缩放将时间序列转化为token序列,语言模型使用交叉熵损失在这些token上进行训练。训练完成后,通过给定历史上下文采样多条未来轨迹来获得概率预测。Chronos模型已在大量公开时间序列数据及高斯过程生成的合成数据上进行训练。
关于Chronos模型细节、训练数据与流程及实验结果,请参阅论文《Chronos:学习时间序列的语言》。
图1:Chronos核心架构示意图。(左)输入时间序列经缩放量化转为token序列。(中)token输入语言模型(编码器-解码器或纯解码架构),模型通过交叉熵损失训练。(右)推理时自回归采样模型输出的token并映射回数值,通过多次采样轨迹获得预测分布。
模型架构
本仓库模型基于T5架构,主要差异在于词汇表大小:Chronos-T5采用4096个token(原版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,
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许可证。