Crossformer: Cross-Dimension Dependency Transformer for Multivariate Time Series Forecasting

Machine Learning
Introduced by
Yunhao Zhang & Junchi Yan
Year
2023
Type
Transformer-based multivariate time-series forecasting model
Family
Time-series forecasting

What does it do?

Crossformer is a Transformer-based model for multivariate time series forecasting, introduced by Yunhao Zhang and Junchi Yan at ICLR 2023.

Many forecasting Transformers process each variate separately; Crossformer adds an explicit attention stage across variates, so inter-variate dependencies are modelled alongside temporal patterns. It applies two attention stages, cross-time and then cross-dimension, to segment-level embeddings arranged in a hierarchical encoder.

The intuition behind the method

Consider a dataset with many sensors recorded over time. Many forecasting Transformers examine each sensor's series separately and so miss the fact that sensors often influence one another. Crossformer alternates two attention stages: first across time segments within each variate, then across all variates at each time step. Stacking these blocks, with segments merged at each layer, builds representations at progressively coarser temporal scales.

History

Crossformer was proposed by Yunhao Zhang and Junchi Yan and presented at ICLR 2023. It belongs to the period of debate over whether Transformers are well suited to time series forecasting, and over whether channel-independent processing (as in PatchTST) or explicit modelling of dependencies across variates is preferable. Crossformer takes the latter approach.

When to use it

Choose Crossformer when the series are multivariate, the channels co-evolve, and there is reason to expect that one variable carries information about others at corresponding times, as in traffic networks or sensor arrays. It is a reasonable candidate when you want the model to learn such interactions rather than assume them away. Do not expect a gain when the variables are largely unrelated or when the task is dominated by each series' own trend; in those cases channel-independent or simple linear models are natural baselines and can be stronger. Because segment length and lookback length both need tuning, budget time for that before comparing results. PatchTST and iTransformer, which appear among this page's related methods, are alternatives to evaluate against.

Limitations and considerations

  • The cross-dimension stage attends over all D variates at every segment position, so weakly related or uninformative variables can add noise to the representation
  • Segment length L_seg sets the granularity of tokens in both attention stages and must be tuned per dataset
  • The hierarchical schedule doubles segment length at each layer, a fixed coarsening pattern that may not match every sampling rate or periodicity
  • Cost grows with both the number of variates D and the number of segments N; unrestricted attention across variates is quadratic in D, so with many variates check memory and runtime before choosing the model

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

Strengths

  • Models temporal dependencies within each variate and cross-variate dependencies in one architecture, through two attention stages applied in sequence
  • Hierarchical merging gives deeper layers coarser segment tokens, so longer temporal context is covered without treating every time step as a token
  • Attending over segment embeddings rather than individual time steps shortens the sequence the attention layers process
  • Addresses the channel-independence assumption of models such as PatchTST, so inter-variate structure can be used when it is present

Applications

  • Traffic speed and flow forecasting across road network sensors
  • Electricity consumption prediction from multiple meters or substations
  • Weather forecasting with correlated meteorological variables
  • Exchange rate and financial index joint forecasting
  • Industrial IoT sensor network monitoring and anomaly-aware forecasting

How it works

How it works

1

The input series, with D dimensions and T time steps, is split into segments of fixed length L_seg, and each segment of each variate is linearly projected into a d_model-dimensional embedding. The result is a short sequence of segment tokens for each variate, rather than one token per time step. This shortens the sequence the attention layers must process and gives each token a local summary of a temporal window.

Formula
\text{Given input } \mathbf{X} \in \mathbb{R}^{D \times T}, \text{ split each variate into segments of length } L_\text{seg}, \text{ embed each segment via linear projection: } \mathbf{E}^{(d)}_t = \text{Embed}\bigl(\mathbf{X}^{(d)}_{tL_\text{seg}:(t+1)L_\text{seg}}\bigr) \in \mathbb{R}^{d_\text{model}}
2

For each dimension separately, self-attention runs over that variate's N segment embeddings, using queries, keys and values obtained from the learned projections W_Q, W_K and W_V. This stage models temporal dependencies within a single variate. No information is exchanged between variates at this point.

Formula
\text{Cross-Time Stage: for each dimension } d, \text{ apply self-attention over its } N = \lceil T/L_\text{seg} \rceil \text{ segment embeddings: } \mathbf{H}^{(d)} = \text{Attention}\bigl(\mathbf{E}^{(d)} \mathbf{W}_Q,\; \mathbf{E}^{(d)} \mathbf{W}_K,\; \mathbf{E}^{(d)} \mathbf{W}_V\bigr)
3

At each segment position, attention runs across the D variates, using the cross-time outputs as tokens and a second set of projections (W'_Q, W'_K, W'_V). This is the stage that lets a variate's representation at a given position depend on the other variates, which channel-independent models do not do. The formula on this page is written as plain attention across all D variates and is a schematic. Full attention across variates costs quadratic time in D, so implementations for high-dimensional data may use a more economical variant of this stage; check the original paper for the exact design.

Formula
\text{Cross-Dimension Stage: at each time step } t, \text{ apply attention across all } D \text{ dimensions: } \mathbf{G}_t = \text{Attention}\bigl(\mathbf{H}_{:,t} \mathbf{W}_Q^{\prime},\; \mathbf{H}_{:,t} \mathbf{W}_K^{\prime},\; \mathbf{H}_{:,t} \mathbf{W}_V^{\prime}\bigr)
4

Between encoder layers, adjacent segment tokens are merged so that the effective segment length doubles at each layer, giving deeper layers coarser temporal tokens that span longer windows. The final representations G^(L) are then mapped to H future steps, producing an output of shape D by H. The linear map W_out in the formula is a simplified schematic of this forecasting head; the published model uses a more elaborate decoder, so consult the original paper for its exact form.

Formula
\text{Hierarchical Segment Merging doubles the segment length at each encoder layer: } L_\text{seg}^{(l)} = 2 \cdot L_\text{seg}^{(l-1)},\text{ and the forecasting head projects the final representations to } H \text{ future steps: } \hat{\mathbf{Y}} = \mathbf{G}^{(L)} \mathbf{W}_\text{out} \in \mathbb{R}^{D \times H}

Common pitfalls

  • Assuming cross-dimension attention always helps: on datasets where variates are largely independent, channel-independent models can outperform Crossformer
  • Choosing segment length without tuning: a poor value affects both the cross-time and cross-dimension stages, because both operate on the same segment tokens
  • Evaluating only against Transformer baselines: include a simple linear baseline such as DLinear, which can be competitive on some datasets
  • Tuning lookback window and segment length separately: the hierarchical structure depends on the input length, so the two should be tuned together
  • Unfair evaluation: normalise with training-set statistics only, use a chronological train/validation/test split to avoid leakage, and repeat runs over several random seeds

Frequently asked questions

How does Crossformer differ from PatchTST?

PatchTST applies patch-based attention independently per variate (channel independence), which can work well when inter-variable correlations are weak. Crossformer explicitly adds a cross-dimension attention stage to capture inter-variate dependencies, making it more expressive on correlated multivariate datasets. The extra capacity may also fit spurious cross-variate patterns, particularly on small datasets, so check with held-out validation and compare against a channel-independent baseline.

What is the role of the segment length hyperparameter?

The segment length L_seg controls the granularity of temporal tokens fed into the two-stage attention. Shorter segments capture finer-grained temporal patterns but increase sequence length and computational cost, while longer segments provide coarser summaries with lower cost. It must be tuned per dataset and interacts with the hierarchical merging schedule across encoder layers.

Is Crossformer always better than linear forecasting baselines?

No. Simple linear models such as DLinear can be competitive with Transformer-based models on some benchmarks, depending on the dataset, particularly when inter-variate dependencies are weak or the task is largely trend-driven. Crossformer is more likely to help where cross-dimension structure is present and useful for prediction.

Related methods

Sources

  1. Zhang, Y., & Yan, J. (2023). Crossformer: Transformer utilizing cross-dimension dependency for multivariate time series forecasting. ICLR.

    Open publication reference