Non-stationary Transformer

Machine Learning
Introduced by
Yong Liu et al.
Year
2022
Type
Transformer-based time-series forecasting model
Family
Time-series forecasting

What does it do?

Non-stationary Transformer is a Transformer-based time-series forecasting architecture introduced by Yong Liu, Haixu Wu, Jianmin Wang, and Mingsheng Long at NeurIPS 2022.

It targets a tension in applying Transformers to non-stationary series: normalizing the inputs stabilizes training, but the same normalization can remove level and scale information that helps prediction. The model normalizes each input sequence, applies de-stationary attention that re-injects the removed statistics, and rescales the forecast to the original distribution.

The intuition behind the method

Imagine normalizing a stock price series before feeding it to a Transformer: the model loses knowledge of the overall trend and scale. Non-stationary Transformer normalizes the input, which keeps training stable, and then passes the removed statistics back into the attention computation, so the model can still account for how non-stationary the original data was. The output is rescaled to recover the original level and magnitude. The design aims to combine training stability with accuracy on non-stationary signals.

History

Vanilla Transformer models achieved strong results in natural language processing but were less established on real-world time series, which often show trends and shifting levels. Earlier Transformer forecasters such as Informer and Autoformer addressed computational cost and series decomposition, respectively, but did not target stationarity directly. Liu et al. (NeurIPS 2022) framed the problem as over-stationarization and proposed the Non-stationary Transformer, which combines series stationarization with de-stationary attention as a remedy.

When to use it

Choose Non-stationary Transformer when forecasting a univariate or multivariate series whose level, trend, or variance changes over time, and the forecast is multi-step over medium to long horizons. It assumes a fixed-length look-back window, and the statistics computed from that window must be informative, so very short windows are a poor fit. It also needs enough training data to fit the Transformer layers. If the series are already stable in level and scale, or the history is too short to train a deep model, a simpler statistical or linear forecaster is a more defensible starting point.

Limitations and considerations

  • The attention is the standard softmax form in the mechanics, so its cost grows quadratically with the look-back length, which limits very long windows unless the attention is approximated.
  • Gains over simple linear forecasters are not guaranteed and may be small on some datasets, so a baseline comparison is needed.
  • Tuning involves the look-back length along with the usual depth, width and learning-rate choices.
  • As a deep encoder-decoder model, it requires more training data and compute than classical statistical forecasters.

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

Strengths

  • Normalizes each input window, so inputs with different levels and scales enter the Transformer in a comparable range.
  • The de-stationary step adds learned factors inside the attention computation, so it can be placed within a standard attention layer.
  • Keeps trend and scale information available to the attention step instead of discarding it together with the normalization.
  • The original paper evaluates the model on long-range forecasting benchmarks against Transformer-family baselines.

Applications

  • Electricity and energy load forecasting with trending consumption patterns
  • Financial time-series prediction (prices, volatility) with non-constant means
  • Weather and climate variable forecasting over multi-step horizons
  • Traffic flow prediction on road networks with trend components
  • Industrial sensor monitoring where process drift is common

How it works

How it works

1

Each input window is normalized using its own mean (mu) and standard deviation (sigma), computed over the T time steps of that window. This per-sequence normalization differs from global dataset normalization, which uses statistics over the whole training set. The window statistics are kept so that they can be used again after prediction.

Formula
\hat{x}_t = \frac{x_t - \mu}{\sigma}, \quad \mu = \frac{1}{T}\sum_{t=1}^{T} x_t, \quad \sigma = \sqrt{\frac{1}{T}\sum_{t=1}^{T}(x_t - \mu)^2}
2

De-stationary attention modifies the attention computation using two learnable factors, tau and delta, which are derived from the mean and standard deviation removed during stationarization. Their role is to let the attention reflect the original level and scale of the window, rather than only the normalized values. Tau and delta are trained end to end with the rest of the model. The precise way these factors enter the attention logits is defined in the original NeurIPS 2022 paper and should be taken from there before implementation.

Formula
\text{Attn}(Q, K, V) = \text{Softmax}\!\left(\frac{(\tau Q)(\delta + K)^\top}{\sqrt{d_k}}\right) V
3

After the encoder-decoder stack produces normalized predictions, each output is multiplied by the stored standard deviation and shifted by the stored mean. This maps the forecast back to the level and magnitude of the original series.

Formula
\hat{y}_t = \sigma \cdot \tilde{y}_t + \mu
4

A linear projection maps the decoder output to the H-step forecast horizon. Training minimizes the mean squared error between predicted and observed future values over the horizon, with gradients flowing through all components, including the tau and delta operators.

Formula
\mathcal{L} = \frac{1}{H}\sum_{h=1}^{H}\|\hat{y}_{T+h} - y_{T+h}\|^2

Common pitfalls

  • Confusing per-sequence stationarization with global dataset normalization. The mean and standard deviation must be computed from each input window, including at inference time, not from the training set.
  • Using a look-back window so short that mu and sigma are poorly estimated, which leaves the de-stationary attention with little non-stationary information to restore.
  • Applying it to series with stable level and scale, where the window statistics carry little information and the de-stationary step has little to restore. Compare against a stationary baseline first.
  • Evaluating errors on the normalized scale. Metrics must be computed after the statistics-recovery step, otherwise forecast errors in the original units are hidden.

Frequently asked questions

How is series stationarization different from standard z-score normalization?

Standard z-score normalization typically uses global statistics computed over the entire training set. Series stationarization in Non-stationary Transformer uses per-sequence statistics — mean and standard deviation computed from each individual input window. This means each sample is normalized relative to itself, preserving relative within-window patterns while removing local level and scale, and the removed statistics are stored for later recovery.

What are the tau and delta operators in de-stationary attention?

Tau and delta are learnable factors derived from the statistics removed during stationarization. They modify the attention computation so that the attention weights can reflect the original temporal behaviour of the window rather than only the normalized values. Their exact parameterization is given in the original paper and should be taken from there.

Can Non-stationary Transformer be applied to univariate series?

Yes. The normalization formulas in the mechanics are defined for a single series, so a univariate series passes through the same stationarization, attention and recovery steps. Its advantage over simpler models is not guaranteed on every univariate dataset, so compare it against a simple baseline on your own data before adopting it.

Related methods

Sources

  1. Liu, Y., Wu, H., Wang, J., & Long, M. (2022). Non-stationary transformers: Exploring the stationarity in time series forecasting. NeurIPS.

    Open publication reference