UnitNorm: Rethinking Normalization for Transformers in Time Series

Nan Huang, Christian Kümmerle, Xiang Zhang

Abstract

Normalization techniques are crucial for enhancing Transformer models' performance and stability in time series analysis tasks, yet traditional methods like batch and layer normalization often lead to issues such as token shift, attention shift, and sparse attention. We propose UnitNorm, a novel approach that scales input vectors by their norms and modulates attention patterns, effectively circumventing these challenges. Grounded in existing normalization frameworks, UnitNorm's effectiveness is demonstrated across diverse time series analysis tasks, including forecasting, classification, and anomaly detection, via a rigorous evaluation on 6 state-of-the-art models and 10 datasets. Notably, UnitNorm shows superior performance, especially in scenarios requiring robust attention mechanisms and contextual comprehension, evidenced by significant improvements by up to a 1.46 decrease in MSE for forecasting, and a 4.89% increase in accuracy for classification. This work not only calls for a reevaluation of normalization strategies in time series Transformers but also sets a new direction for enhancing model performance and stability. The source code is available at https://anonymous.4open.science/r/UnitNorm-5B84.

Introduction

Transformers have become the dominant architecture for Time Series Analysis (TSA). However, they inherit Layer Normalization (LayerNorm) from Natural Language Processing, which may be suboptimal for temporal data. Standard normalization involves "centering and scaling"—subtracting the mean and dividing by the standard deviation. In TSA, the centering step can be catastrophic. Since attention mechanisms rely on dot products between Queries and Keys, shifting vectors to zero mean can flip their orientation, leading to an "identity crisis" where relational dynamics are distorted.

The Challenges of Traditional Normalization

The paper identifies three primary challenges induced by standard normalization in time series Transformers:

  1. Token Shift: Centering projects vectors onto a hyperplane, frequently flipping the sign of their dot products and altering their relative positions.
  2. Attention Shift: Distorted vector orientations lead to attention weights that do not reflect the original data's relationships.
  3. Sparse Attention: Traditional methods often force "one-hot" attention patterns, causing the model to ignore broader context and periodic patterns essential for forecasting.

Proposed Method: UnitNorm

To address these issues, we introduce UnitNorm (UN), a centering-free normalization method designed as a drop-in replacement for LayerNorm and BatchNorm.

Comparison of normalization techniques across dimensions L (length), D (dimension), and N (batch). UnitNorm (right) operates on individual vectors without centering, preserving directional information.

UnitNorm omits the centering operation entirely, preserving the original direction of input vectors. The transformation is defined as:

$$UN(\mathbf{X}) = D^{k/2} \frac{\mathbf{X}}{\|\mathbf{X}\|_2}$$

Key innovations include:

  • No Centering: By skipping mean subtraction, it eliminates "token shift." The authors mathematically prove that centering has at least a 40% probability of flipping the sign of a dot product between independent Gaussian vectors.
  • Norm-Based Scaling: Vectors are scaled by their $\ell_2$ norm rather than variance.
  • The $k$ Factor: A tunable hyperparameter $k$ modulates attention sparsity. This provides a mathematical guarantee against "attention collapse" by maintaining an Entropy Lower Bound (ELB), ensuring the model captures seasonality and trends.

Experimental Evaluation

We evaluated UnitNorm across 10 diverse datasets using 6 state-of-the-art models, including PatchTST, Crossformer, and FEDformer. The tasks spanned long-term forecasting (e.g., ETTh1, ECL), classification (e.g., Heartbeat, PEMS-SF), and anomaly detection (MSL).

Key Results

  • Forecasting: UnitNorm achieved a significant 1.46 decrease in Mean Squared Error (MSE) on the ETTh2 dataset, showing particular strength in long-horizon tasks where maintaining periodic context is hardest.
  • Classification: Accuracy improved by up to 4.89% on the UWaveGestureLibrary dataset.
  • Anomaly Detection: We observed a 7.32% increase in recall, suggesting that by not distorting the data, the model is much better at spotting subtle deviations.
  • Stability: Empirical tests confirmed that UnitNorm preserves high-entropy attention scores, whereas BatchNorm and LayerNorm often lead to sparse, less informative distributions.

Conclusion

UnitNorm addresses the fundamental flaws of centering in time series normalization. By preserving vector directions and providing a mechanism to control attention sparsity, it significantly enhances the performance and stability of Transformers in TSA. This work sets a new direction for normalization strategies, emphasizing the importance of directional integrity in temporal modeling.

Summary updated

BibTeX
@misc{huang2024unitnorm,
  author = {Nan Huang and Christian Kümmerle and Xiang Zhang},
  title = {{UnitNorm: Rethinking Normalization for Transformers in Time Series}},
  year = {2024},
  eprint = {2405.15903},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2405.15903},
}
Figure