NeurIPS 2026Coming to NeurIPS in Sydney?Explore papers, orals & directions

Self-attention as an attractor network: transient memories without backpropagation

Francesco D'Amico, Matteo Negri

This paper, recently uploaded to arXiv, explores a fascinating bridge between the world of high-performance AI (Transformers) and theoretical physics (attractor networks). Here is a summary of their findings.

TL;DR

Researchers have successfully mapped the self-attention mechanism of Transformers to the dynamics of a physical "vector spin" system. By treating tokens as spins and the attention update as an energy-minimization step, they developed a recurrent model that can be trained without backpropagation using pseudo-likelihood methods, revealing that "memories" in these networks exist as transient states during the system's evolution.

What Problem Does This Paper Address?

While Transformers are the backbone of modern AI, we still struggle to understand why they work so well from a first-principles perspective.

In physics, we often use Hopfield networks—systems that store memories as "attractors" (stable states that the system naturally falls into). Previous research successfully linked cross-attention (where one sequence looks at another) to these networks. However, self-attention (where a sequence looks at itself, as in GPT models) has been harder to describe using a simple energy function because the "queries" and "keys" are constantly changing.

The authors aim to bridge this gap by providing a mathematical framework that treats self-attention as a physical system seeking to minimize its local energy.

Methods

The authors propose a "Bare Self-Attention" model based on three key pillars:

  1. Tokens as Vector Spins: Instead of seeing tokens merely as data points, they treat each token as a $d$-dimensional "vector spin" on a sphere.
  2. Local Energy Functions: They define the update rule for self-attention as the derivative of a pseudo-likelihood energy function. In this view, each token tries to orient itself to minimize its energy based on the "local field" created by all other tokens in the sequence.
  3. Backpropagation-Free Training: Because the model is framed as a physical system, they don't need standard backpropagation. Instead, they train the coupling matrices ($J_{ij}$) by minimizing the negative pseudo-likelihood of the training data. This is essentially "teaching" the network the statistical structure of the data without unrolling a computational graph.

The model is used recurrently, meaning the same single layer is applied over and over to the input until the system evolves toward a state.

Datasets

The researchers tested their framework on the MNIST dataset (50,000 images of handwritten digits). While simple, MNIST provides a clear way to visualize how the model reconstructs or "denoises" visual information. They evaluated the model on two specific tasks:

  • Masked Token Prediction: Reconstructing an image where 30% of the pixels (tokens) are missing.
  • Denoising: Removing heavy Gaussian noise from an image.

Key Insights and Ideas

  • Transient Memories: This is the most striking finding. Unlike traditional Hopfield networks where you want the system to stay at the "memory" forever, these networks show non-monotonic behavior. The error (MSE) drops as the system moves toward the correct image (a transient state) but then increases as the system continues to evolve toward a global attractor.
  • The Global Attractor: Left to run for too long, the "Bare Self-Attention" model eventually converges to a blurry image that looks like the average of all MNIST digits. The "useful" information is found in the journey, not the final destination.
  • The Role of the MLP: By comparing their "Bare" model to a full Transformer block, they realized that the Multi-Layer Perceptron (MLP) typically found in Transformers is crucial for modulating signals within patches. Without the MLP, the model struggles with borders and tends to make patches too uniform.

Key Results

  • Task Performance: The Bare Self-Attention model successfully performed both masked prediction and denoising. In masked prediction, it reached its optimal state in just one iteration. In denoising, it required about 10 iterations to find the "transient memory" of the digit.
  • Comparison: While a standard 5-layer Vision Transformer (ViT) trained with backpropagation achieved lower error, the Bare Self-Attention model remained competitive with a "repeated transformer block" while being significantly simpler and more theoretically transparent.
  • Task-Agnostic Training: Unlike the benchmark Transformers, which had to be trained separately for denoising and masking, the authors' model was trained once on the data distribution and could handle both tasks "out of the box."

Limitations and Future Work

  • Fixed Sequence Length: The current framework uses a coupling tensor that depends on the specific positions of tokens ($N \times N$), making it difficult to apply to variable-length sequences (like text) without a more sophisticated approach to positional encoding.
  • Memory Scaling: The $N \times N \times d \times d$ coupling tensor is large and potentially difficult to scale to massive datasets or high-resolution images.
  • Missing Components: The model currently excludes trainable embeddings and MLPs to keep the physics tractable. The authors suggest that finding a way to include these components in the pseudo-likelihood training framework is a key next step.

Overall, the paper provides a compelling "physics-first" look at Transformers, suggesting that the secrets to their success might lie in the complex, transient dynamics of attractor networks.

Summary updated

Abstract

Transformers are one of the most successful architectures of modern neural networks. At their core there is the so-called attention mechanism, which recently interested the physics community as it can be written as the derivative of an energy function in certain cases: while it is possible to write the cross-attention layer as a modern Hopfield network, the same is not possible for the self-attention, which is used in the GPT architectures and other autoregressive models. In this work we show that it is possible to obtain the self-attention layer as the derivative of local energy terms, which resemble a pseudo-likelihood. We leverage the analogy with pseudo-likelihood to design a recurrent model that can be trained without backpropagation: the dynamics shows transient states that are strongly correlated with both train and test examples. Overall we present a novel framework to interpret self-attention as an attractor network, potentially paving the way for new theoretical approaches inspired from physics to understand transformers.
BibTeX
@inproceedings{damico2024self,
  author = {Francesco D'Amico and Matteo Negri},
  title = {{Self-attention as an attractor network: transient memories without backpropagation}},
  booktitle = {COMPENG},
  year = {2024},
  url = {https://openreview.net/forum?id=wH0rkd0sWx},
}

Loading related content...

Figure