Temporal Fusion Transformer

Machine Learning
Introduced by
Lim, B., Arık, S. Ö., Loeff, N. & Pfister, T.
Year
2021
Type
Attention-based deep learning forecasting architecture

What does it do?

The Temporal Fusion Transformer (TFT), introduced by Lim, Arık, Loeff and Pfister in 2021, is an attention-based deep learning architecture for multi-horizon time series forecasting that is designed to expose how it uses its inputs.

It takes static covariates, observed past inputs and known-future inputs together, and produces multi-step forecasts as quantile ranges rather than single values. Its interpretability comes mainly from variable selection, gating and interpretable self-attention.

The intuition behind the method

Real-world forecasting mixes several kinds of information: attributes that never change (like a store's location), measurements observed only up to now (like past sales), and inputs known in advance for the future (like holidays or planned promotions). TFT learns which of these inputs actually matter, focuses attention on the most relevant past time steps, and outputs not a single number but a range of quantiles — so you see both the prediction and its uncertainty.

History

Bryan Lim, Sercan Arık, Nicolas Loeff and Tomas Pfister introduced the Temporal Fusion Transformer in 2021 in the International Journal of Forecasting, with interpretability for deep multi-horizon forecasting as an explicit aim. Lim and Zohren's 2021 survey reviews encoder and decoder designs used in deep learning for one-step-ahead and multi-horizon forecasting, which is the broader context for TFT. The survey also covers hybrid models that combine statistical and neural components.

When to use it

Choose TFT for multi-step forecasting of time series or panel data when you have historical covariates and known-future covariates, such as planned promotions or scheduled events, and you need forecasts for several horizons with uncertainty bands. It fits when you have a substantial amount of training data, enough for the variable-selection and attention outputs to be stable, and when a GPU is available. How much data is enough depends on the dataset and should be checked by validation. With very short series or no covariates, compare simpler baselines such as ARIMA first; they are often a safer starting point. TFT accepts static, past and known-future inputs, including categorical variables.

Limitations and considerations

  • The stability of the variable-selection and attention outputs depends on the amount of training data; with limited observations these interpretability outputs should be read with caution, and the amount needed depends on the dataset.
  • Very short series give limited information for a high-capacity model, so simpler baselines such as ARIMA should be compared first and are often a safer starting point.
  • The architecture is computationally heavy and a GPU is recommended, so training costs more than for classical forecasting methods.
  • Historical and future covariates must be explicitly defined and supplied; poorly specified covariates limit what the model can use.
  • Attention and variable-selection weights are diagnostics of what the model relies on, not causal effects on the target.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Processes static, observed-past and known-future covariates in one architecture, so information known in advance can inform the forecast horizon.
  • Variable-selection weights and attention patterns are inspectable outputs, not only a forecast.
  • Quantile outputs give prediction bands across the horizon rather than a single point forecast.
  • Produces forecasts for several steps ahead within one model.
  • Combines recurrent layers for local patterns with self-attention for longer-range dependencies, as described by its authors, and accepts mixed continuous and categorical inputs.

Applications

  • Multi-step demand or sales forecasting where planned drivers, such as promotions, are known ahead of time.
  • Energy, weather or traffic forecasting in which some drivers are scheduled or otherwise known in advance.
  • Panel forecasting across many related series that share static attributes.
  • Forecasting tasks where both prediction intervals and interpretable drivers are required.

How it works

How it works

1

Variable selection components weigh the contribution of each input feature across the static, observed-past and known-future covariates. Gating layers can suppress components that add little to the forecast. The resulting selection weights are one of the main outputs used to interpret the model.

2

TFT combines recurrent layers, which process local sequential patterns, with interpretable self-attention layers, which capture long-term dependencies across the input window. The attention weights indicate which past time steps the model weights heavily, so the temporal dynamics can be inspected. These weights are diagnostic and do not establish causal drivers of the target.

3

For each quantile q, the loss is max(q(y - ŷ_q), (q - 1)(y - ŷ_q)), where y is the observed target and ŷ_q is the predicted q-th quantile. Training sums this loss over the chosen quantiles, the horizon steps and the training samples, so each output estimates a conditional quantile of the target. The quantile outputs form a prediction band across the forecast horizon. These bands are only as reliable as the fitted quantiles, so check them on held-out data rather than assuming guaranteed coverage.

Formula
\mathcal{L} = \sum_q \max\big(q(y-\hat{y}_q),\,(q-1)(y-\hat{y}_q)\big)

Common pitfalls

  • Applying TFT to a small dataset without checking for overfitting; benchmark it against simpler baselines such as ARIMA or Random Forest using held-out validation before relying on it.
  • Including a 'known-future' covariate whose values are only known after the forecast date, which leaks information into training and inflates apparent accuracy.
  • Reporting only the median or a single point forecast and ignoring the quantile bands, which are the method's uncertainty output.
  • Reading attention or variable-selection weights as causal explanations of the target series.
  • Training on CPU and accepting impractical run times instead of using a GPU.

Frequently asked questions

How much data does TFT need?

There is no universal threshold. The variable-selection and attention outputs need enough data to be stable, and the amount depends on the dataset, so check it with validation. With very short series, compare simpler baselines such as ARIMA first, as they are often a safer starting point.

What makes TFT interpretable?

Its variable-selection components indicate how much each input contributes, and its interpretable self-attention layers indicate which past time steps the model weights heavily. These weights are diagnostics of model behaviour and do not establish causal drivers of the target.

What is the difference between past and future covariates?

Past (observed) covariates are only known up to the present, while known-future covariates, such as holidays or planned events, are available in advance. TFT accepts all three kinds of inputs, static, past and known-future, and the variable-selection step weighs their contributions.

Do I need a GPU?

A GPU is recommended because the architecture is computationally heavy; training on CPU can be impractically slow for realistic series.

Related methods

Sources

  1. Lim, B., Arık, S. Ö., Loeff, N. & Pfister, T. (2021). Temporal Fusion Transformers for Interpretable Multi-Horizon Time Series Forecasting. International Journal of Forecasting, 37(4), 1748–1764.

    Open DOI reference
  2. Lim, B. & Zohren, S. (2021). Time-Series Forecasting with Deep Learning: A Survey. Philosophical Transactions of the Royal Society A, 379(2194), 20200209.

    Open DOI reference