---
title: "Probabilistic Time Series Forecasting with 🤗 Transformers"
description: "An encoder-decoder Transformer can be trained as a global probabilistic forecaster that learns across many related time series and outputs a distribution (Student-t by default) rather than point estimates, with forecasts sampled autoregressively."
url: "https://swe.quest/articles/probabilistic-time-series-forecasting-with-transformers-d4a4a66f913813a3"
canonical: "https://huggingface.co/blog/time-series-transformers"
source: "Hugging Face"
published: "2022-12-01"
difficulty: "hard"
kind: "How-to"
reading_minutes: 19
tags: ["machine-learning","model-training","python"]
---

# Probabilistic Time Series Forecasting with 🤗 Transformers

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-12-01, 19 min read, How-to. Original: [https://huggingface.co/blog/time-series-transformers](https://huggingface.co/blog/time-series-transformers)

## Summary

An encoder-decoder Transformer can be trained as a global probabilistic forecaster that learns across many related time series and outputs a distribution (Student-t by default) rather than point estimates, with forecasts sampled autoregressively. The walkthrough trains Hugging Face's TimeSeriesTransformerForPrediction from scratch on the Monash tourism\_monthly dataset (366 Australian regions, 24-month horizon). It uses GluonTS for lag features, time features, observed-value masks and instance splitting into context/prediction windows. Transformers suit forecasting because they handle missing values via attention masks and train with teacher forcing, but quadratic attention limits window sizes and they can overfit more easily.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- Transformer encoder-decoder architecture ([easy posts on System design](https://swe.quest/tags/system-design.md?difficulty=easy))
- PyTorch training loops ([easy posts on Model training](https://swe.quest/tags/model-training.md?difficulty=easy))
- probability distributions
- time series basics

## Keywords

Hugging Face Transformers, Time Series Transformer, GluonTS, Monash Time Series Forecasting, tourism\_monthly, Student-t distribution

## Related posts

- [Multivariate Probabilistic Time Series Forecasting with Informer](https://swe.quest/articles/multivariate-probabilistic-time-series-forecasting-with-informer-6e926e78b9077796.md): Hugging Face · 2023-03-10 · Hard · 21 min read · Machine learning, Model training, Python
  Informer, the AAAI'21 best paper model now in Hugging Face Transformers, extends the vanilla Transformer for long-sequence time series forecasting with two changes: ProbSparse attention, which uses a query sparsity measurement on sampled keys to keep only the top c·log T "active" queries and cut attention cost from O(T²) to O(T log T), and a distilling step (Conv1d + ELU + MaxPool) that halves sequence length between encoder layers to reduce memory to O(N·T log T).
- [TimesFM-3: A zero-shot foundation model for multivariate forecasting](https://swe.quest/articles/timesfm-3-a-zero-shot-foundation-model-for-multivariate-forecasting-c2421e383bcd85af.md): Google Research · 2026-08-31 · Hard · 6 min read · Machine learning, Model training, Inference & serving
  TimesFM-3 is a 330M-parameter decoder-only transformer pre-trained on over 1 trillion real and synthetic time points that does zero-shot multivariate forecasting, supporting multiple targets, past-only covariates and known-future covariates.
- [Yes, Transformers are Effective for Time Series Forecasting (+ Autoformer)](https://swe.quest/articles/yes-transformers-are-effective-for-time-series-forecasting-autoformer-7c2e6db2d5fb67fd.md): Hugging Face · 2023-06-16 · Hard · 20 min read · Machine learning, Python, Evaluation
  Univariate Autoformer beats the DLinear linear model on Traffic (MASE 0.910 vs 0.965), Exchange-Rate (1.087 vs 1.690) and Electricity (0.751 vs 0.831) when compared at equivalent size and in the same setting, countering the AAAI 2023 claim that Transformers are ineffective for time series forecasting.
- [Patch Time Series Transformer in Hugging Face](https://swe.quest/articles/patch-time-series-transformer-in-hugging-face-94fa5d56a8b80388.md): Hugging Face · 2024-02-01 · Medium · 13 min read · Machine learning, Model training, Python
  PatchTST splits each univariate channel of a time series into subseries-level patches that act as Transformer tokens.
- [Train your first Decision Transformer](https://swe.quest/articles/train-your-first-decision-transformer-d9877713a380ce1a.md): Hugging Face · 2022-09-08 · Hard · 8 min read · Model training, Machine learning, Python
  Decision Transformers recast reinforcement learning as conditional sequence modeling: a GPT-2 model takes the last K timesteps of return-to-go, state and action tokens and autoregressively predicts actions that achieve a desired return.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
