Skip to main content

ChatTime: A Multimodal Time Series Foundation Model

Project description

ChatTime: A Multimodal Time Series Foundation Model

preprint huggingface huggingface Visits Badge Stars Forks

✨ Introduction

Human experts typically integrate numerical and textual multimodal information to analyze time series. However, most traditional deep learning predictors rely solely on unimodal numerical data, using a fixed-length window for training and prediction on a single dataset, and cannot adapt to different scenarios. The powered pre-trained large language model has introduced new opportunities for time series analysis. Yet, existing methods are either inefficient in training, incapable of handling textual information, or lack zero-shot forecasting capability. In this paper, we innovatively model time series as a foreign language and construct ChatTime, a unified framework for time series and text processing. As an out-of-the-box multimodal time series foundation model, ChatTime provides zero-shot forecasting capability and supports bimodal input/output for both time series and text. We design a series of experiments to verify the superior performance of ChatTime across multiple tasks and scenarios, and create four multimodal datasets to address data gaps. The experimental results demonstrate the potential and utility of ChatTime. Specifically, in the unimodal zero-shot forecasting task, ChatTime achieves 99.9% of the previous state-of-the-art using only 4% of the pre-training data. In the multimodal tasks of context-guided forecasting and time series question answering, ChatTime outperforms the previous state-of-the-art by 3.7% and 36.6%, respectively.

📪 How to install

pip install chat-time==0.2.0

📪 How to produce a new release

# Update version in file src/chat_time/__about__
python -m build
# This should produce a dist folder with a wheel and a tar file
twine upload --verbose dist/* # Add the PyPIP token to upload a new version

📈 Usage

We present three minimal examples showing how to perform the multimodal time series analysis using the ChatTime model. The code and corresponding results are available in the notebook.

Zero-Shot Time Series Forecasting

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from model.model import ChatTime

dataset = "Traffic"
hist_len = 120
pred_len = 24
model_path = "ChengsenWang/ChatTime-1-7B-Chat"

df = pd.read_csv(f"./dataset/{dataset}.csv")
hist_data = np.array(df["Hist"].apply(eval).values.tolist())[:, -hist_len:][0]
pred_data = np.array(df["Pred"].apply(eval).values.tolist())[:, :pred_len][0]

model = ChatTime(hist_len=hist_len, pred_len=pred_len, model_path=model_path)

out = model.predict(hist_data)

hist_x = np.linspace(0, hist_len-1, hist_len)
pred_x = np.linspace(hist_len, hist_len+pred_len-1, pred_len)

plt.figure(figsize=(8, 2), dpi=500)
plt.plot(hist_x, hist_data, color='#000000')
plt.plot(pred_x, pred_data, color='#000000', label='true')
plt.plot(pred_x, out, color='#FF7F0E', label='pred')
plt.axvline(hist_len, color='red')
plt.legend(loc="upper left")
plt.show()

Context-Guided Time Series Forecasting

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from chat_time.model.model import ChatTime

dataset = "PTF"
hist_len = 120
pred_len = 24
model_path = "ChengsenWang/ChatTime-1-7B-Chat"

df = pd.read_csv(f"./dataset/{dataset}.csv")
hist_data = np.array(df["Hist"].apply(eval).values.tolist())[:, -hist_len:][0]
pred_data = np.array(df["Pred"].apply(eval).values.tolist())[:, :pred_len][0]
context = df["Text"].values[0]

model = ChatTime(hist_len=hist_len, pred_len=pred_len, model_path=model_path)

out_text = model.predict(hist_data, context)
out = model.predict(hist_data)

hist_x = np.linspace(0, hist_len-1, hist_len)
pred_x = np.linspace(hist_len, hist_len+pred_len-1, pred_len)

plt.figure(figsize=(8, 2), dpi=500)
plt.plot(hist_x, hist_data, color='#000000')
plt.plot(pred_x, pred_data, color='#000000', label='true')
plt.plot(pred_x, out_text, color='#FF7F0E', label='pred_text')
plt.plot(pred_x, out, color='#1F77B4', label='pred')
plt.axvline(hist_len, color='red')
plt.legend(loc="upper left")
plt.show()

Time Series Question Answering

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from chat_time.model.model import ChatTime

dataset = "TSQA"
model_path = "ChengsenWang/ChatTime-1-7B-Chat"

df = pd.read_csv(f"./dataset/{dataset}.csv")
series = np.array(df["Series"].apply(eval).values.tolist())[0]
question = df["Question"].values[0]
answer = df["Answer"].values[0]

model = ChatTime(model_path=model_path)

out = model.analyze(question, series)

plt.figure(figsize=(8, 2), dpi=500)
plt.plot(series, color='#000000')
plt.show()

print(question)
print(f"\n{out} / {answer}\n")

Continuous Pre-Training and Instruction Fine-Tuning

The code for Continuous Pre-Training and Instruction Fine-Tuning for ChatTime is located within the training folder, while the model weights are available at ChengsenWang/ChatTime-1-7B-Base and ChengsenWang/ChatTime-1-7B-Chat, respectively.

:floppy_disk: Datasets

Refer to following repositories for instructions on downloading and utilizing the datasets.

📝 Citation

If you find this repo or our work useful for your research, please consider citing the paper:

@inproceedings{
  author    = {Chengsen Wang and Qi Qi and Jingyu Wang and Haifeng Sun and Zirui Zhuang and Jinming Wu and Lei Zhang and Jianxin Liao},
  title     = {ChatTime: A Unified Multimodal Time Series Foundation Model Bridging Numerical and Textual Data},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year      = {2025},
}

📪 Contact

If you have any question, please contact cswang@bupt.edu.cn.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chat_time-0.3.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chat_time-0.3.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file chat_time-0.3.0.tar.gz.

File metadata

  • Download URL: chat_time-0.3.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for chat_time-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2da332ad2b7ee71479ba969d9ac5df4bb8c61f97b2a4de5f806be13f688c35db
MD5 b31d53e790d4b2929c88fe7d7705f6d1
BLAKE2b-256 10a38208e5d03a61d60c29aedc7711ac4951604a22eac801fda2e3abe27752f6

See more details on using hashes here.

File details

Details for the file chat_time-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: chat_time-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for chat_time-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a9c90a81c9006dc1682a96a6f26b276ed58a941b5e7e419a5be17229b3356f63
MD5 7347ee3e1a3a16dd2ebc41e55ecf63e5
BLAKE2b-256 8569143207e8c0252e2aec2b5c245e9b32caf0294f89a209d9d75a9654e7da65

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page