Easy attention: A simple self-attention mechanism for Transformers

Marcial Sanchis-Agudo, Yuning Wang, Karthik Duraisamy, Ricardo VinuesaarXiv 2023 · OpenReview

TL;DR

This paper introduces "easy attention," a simplified attention mechanism for Transformers designed to improve temporal prediction of chaotic systems. By removing the need for queries and keys, and directly learning attention scores, easy attention offers reduced complexity and enhanced robustness compared to standard self-attention and LSTMs, particularly for chaotic dynamics.

What Problem Does This Paper Address?

Predicting the behavior of complex, chaotic dynamical systems is a significant challenge across many scientific and engineering fields. Traditional methods and even current deep learning approaches like LSTMs and standard Transformers struggle with the inherent sensitivity to initial conditions and the complex, often non-linear, long-term dependencies present in these systems. While Transformers have shown promise due to their attention mechanisms, the computational cost and potential for overfitting in chaotic scenarios remain concerns. This paper aims to address these limitations by proposing a more efficient and robust attention mechanism tailored for temporal predictions of such systems.

Methods

The core contribution is the "easy attention" mechanism. Unlike standard self-attention, which relies on computing query (Q) and key (K) vectors and then using their dot product followed by a softmax function to derive attention scores, easy attention bypasses the Q and K computation. Instead, it directly learns the attention scores as parameters. This is motivated by an analysis showing that standard self-attention effectively compresses information from queries and keys into the attention score itself.

The authors propose learning an attention score matrix, denoted as 'a', which directly captures temporal dependencies. This approach significantly reduces the number of learnable parameters and computational complexity. They also introduce "sparse easy attention," which further reduces parameters by only learning diagonal or near-diagonal elements of the 'a' matrix. The method is integrated into a Transformer encoder architecture for temporal prediction tasks.

Datasets

The paper evaluates the proposed easy attention mechanism on several datasets:

  • Lorenz System: Generated data from the Lorenz system, a classic three-dimensional chaotic system, used for training and testing.
  • Turbulence Shear Flows: Data from a nine-equation model of near-wall turbulence (Moehlis model) was used.
  • Nuclear Reactor Model: Data from a generic Fluoride-Salt-Cooled High-Temperature Reactor (gFHR) model, a complex industrial system.
  • Sinusoidal Waves: Synthetic data of sine waves with different phase shifts was used for initial validation and reconstruction tasks.

Key Insights and Ideas

  • Attention Scores as Direct Learnable Parameters: The key insight is that the complex computations involving queries and keys in standard self-attention might be unnecessary for capturing temporal dependencies in chaotic systems. Directly learning the attention scores ('a' matrix) proves to be more efficient and effective.
  • Reduced Complexity for Chaotic Systems: By eliminating Q and K computations and the softmax function, easy attention significantly reduces computational cost and the number of parameters, making it more suitable for complex, high-dimensional chaotic systems.
  • Robustness to Chaos: The paper argues that easy attention's input-independent nature (once trained) makes it more robust to the inherent unpredictability and sensitivity of chaotic systems, as it learns a fixed "optimal temporal basis" rather than adapting dynamically to potentially noisy inputs at inference time.
  • Koopman Operator Connection: The authors draw parallels between their approach and Koopman operator theory, suggesting that easy attention learns a form of optimal finite-rank operator for approximating system dynamics.

Key Results

  • Lorenz System: Easy attention achieved a significantly lower prediction error (1.99%) compared to self-attention (7.36%) and LSTM (37.68%) for short-term predictions. It also demonstrated superior performance in reproducing the system's attractor geometry and Lyapunov exponent.
  • Turbulence Shear Flows: Easy attention models showed comparable or better performance than LSTM in reconstructing mean velocity profiles and streamwise velocity fluctuations, outperforming self-attention.
  • Nuclear Reactor Model: Easy attention exhibited the best reconstruction capability for core flow dynamics, outperforming sparse easy attention, self-attention, and LSTM in terms of accuracy and oscillation reproduction.
  • Computational Efficiency: Easy attention reduced computational complexity by approximately 50% and saved computation time by 26% compared to self-attention in sinusoidal wave reconstruction tasks.

Limitations and Future Work

  • Assumptions on Temporal Dependencies: The paper acknowledges that the assumption of fixed attention scores (input-independent at inference) might not be universally applicable to all scenarios, especially those where input order is arbitrary or highly variable.
  • Sparsity Trade-off: While sparse easy attention reduces parameters, it can lead to a slight decrease in accuracy, as observed in the Lorenz system's Lyapunov exponent prediction.
  • Future Work: The authors suggest exploring structured or low-rank factorizations of the 'a' matrix for further efficiency, investigating convex penalties for regularization, analyzing the spectral properties of 'a' for stability insights, developing online and adaptive learning methods, and integrating easy attention with classical physics-based operators or reinforcement learning. They also propose exploring multi-scale and multi-modal embeddings and developing better visualization tools for interpretability.

Summary updated

Abstract

To improve the robustness of transformer neural networks used for temporal-dynamics prediction of chaotic systems, we propose a novel attention mechanism called easy attention which we demonstrate in time-series reconstruction and prediction. While the standard self attention only makes use of the inner product of queries and keys, it is demonstrated that the keys, queries and softmax are not necessary for obtaining the attention score required to capture long-term dependencies in temporal sequences. Through the singular-value decomposition (SVD) on the softmax attention score, we further observe that self attention compresses the contributions from both queries and keys in the space spanned by the attention score. Therefore, our proposed easy-attention method directly treats the attention scores as learnable parameters. This approach produces excellent results when reconstructing and predicting the temporal dynamics of chaotic systems exhibiting more robustness and less complexity than self attention or the widely-used long short-term memory (LSTM) network. We show the improved performance of the easy-attention method in the Lorenz system, a turbulence shear flow and a model of a nuclear reactor.
BibTeX
@misc{sanchisagudo2023easy,
  author = {Marcial Sanchis-Agudo and Yuning Wang and Karthik Duraisamy and Ricardo Vinuesa},
  title = {{Easy attention: A simple self-attention mechanism for Transformers}},
  year = {2023},
  eprint = {2308.12874},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2308.12874},
}

Loading related content...

Figure