🚀 Moirai-1.0-R-Base
Moirai是基於掩碼編碼器的通用時間序列預測Transformer,是一個在LOTSA數據上預訓練的大型時間序列模型。如需瞭解Moirai架構、訓練和結果的更多詳細信息,請參考論文。
圖1:Moirai的整體架構。可視化展示的是一個三元時間序列,其中變量0和1是目標變量(即需要進行預測的變量),變量2是動態協變量(預測範圍內的值已知)。基於64的補丁大小,每個變量被劃分為3個標記。補丁嵌入與序列和變量ID一起輸入到Transformer中。陰影部分表示需要預測的預測範圍,其對應的輸出表示被映射到混合分佈參數中。
🚀 快速開始
若要使用Moirai進行推理,需從我們的GitHub倉庫安裝uni2ts庫。
📦 安裝指南
- 克隆倉庫:
git clone https://github.com/SalesforceAIResearch/uni2ts.git
cd uni2ts
- 創建虛擬環境:
virtualenv venv
. venv/bin/activate
- 從源代碼構建:
pip install -e '.[notebook]'
- 創建.env文件:
touch .env
💻 使用示例
基礎用法
以下是一個簡單的入門示例:
import torch
import matplotlib.pyplot as plt
import pandas as pd
from gluonts.dataset.pandas import PandasDataset
from gluonts.dataset.split import split
from uni2ts.eval_util.plot import plot_single
from uni2ts.model.moirai import MoiraiForecast, MoiraiModule
SIZE = "small"
PDT = 20
CTX = 200
PSZ = "auto"
BSZ = 32
TEST = 100
url = (
"https://gist.githubusercontent.com/rsnirwan/c8c8654a98350fadd229b00167174ec4"
"/raw/a42101c7786d4bc7695228a0f2c8cea41340e18f/ts_wide.csv"
)
df = pd.read_csv(url, index_col=0, parse_dates=True)
ds = PandasDataset(dict(df))
train, test_template = split(
ds, offset=-TEST
)
test_data = test_template.generate_instances(
prediction_length=PDT,
windows=TEST // PDT,
distance=PDT,
)
model = MoiraiForecast(
module=MoiraiModule.from_pretrained(f"Salesforce/moirai-1.0-R-{SIZE}"),
prediction_length=PDT,
context_length=CTX,
patch_size=PSZ,
num_samples=100,
target_dim=1,
feat_dynamic_real_dim=ds.num_feat_dynamic_real,
past_feat_dynamic_real_dim=ds.num_past_feat_dynamic_real,
)
predictor = model.create_predictor(batch_size=BSZ)
forecasts = predictor.predict(test_data.input)
input_it = iter(test_data.input)
label_it = iter(test_data.label)
forecast_it = iter(forecasts)
inp = next(input_it)
label = next(label_it)
forecast = next(forecast_it)
plot_single(
inp,
label,
forecast,
context_length=200,
name="pred",
show_label=True,
)
plt.show()
📚 詳細文檔
Moirai家族
引用
如果您在研究或應用中使用了Uni2TS,請使用以下BibTeX進行引用:
@article{woo2024unified,
title={Unified Training of Universal Time Series Forecasting Transformers},
author={Woo, Gerald and Liu, Chenghao and Kumar, Akshat and Xiong, Caiming and Savarese, Silvio and Sahoo, Doyen},
journal={arXiv preprint arXiv:2402.02592},
year={2024}
}
倫理考量
本次發佈僅用於支持學術論文的研究目的。我們的模型、數據集和代碼並非專門為所有下游用途而設計或評估。我們強烈建議用戶在部署此模型之前,評估並解決與準確性、安全性和公平性相關的潛在問題。我們鼓勵用戶考慮人工智能的常見侷限性,遵守適用法律,並在選擇用例時採用最佳實踐,特別是在錯誤或濫用可能對人們的生活、權利或安全產生重大影響的高風險場景中。有關用例的更多指導,請參考我們的AUP和AI AUP。
📄 許可證
本項目採用CC BY-NC 4.0許可證。