cs.LGMar 6, 2026

Stochastic Attention via Langevin Dynamics on the Modern Hopfield Energy

Authors: Abdulrahman Alswaidan, Jeffrey D. Varner

Organizations: R.F. Smith School of Chemical and Biomolecular Engineering Cornell University, Ithaca, NY 14850

Abstract

Attention heads retrieve: given a query, they return a weighted average of stored values. We showed that this computation is one step of gradient descent on the modern Hopfield energy, and that Langevin sampling from the corresponding Boltzmann distribution yielded stochastic attention, a training-free sampler controlled by a single temperature parameter. Lowering the temperature gave exact retrieval; raising it gave open-ended generation. Because the energy gradient equals the attention map, no score network, training loop, or learned model was required, making the approach particularly suited to the low-data regime where learned generative models are starved of training signal. We derived an entropy inflection condition that identified the retrieval-to-generation transition temperature for any memory geometry and validated the sampler on five domains spanning two orders of magnitude in dimension. A single Boolean mask on the attention softmax, identical to the causal mask used in transformers but applied along the memory axis rather than the sequence axis, turned the sampler into a zero-shot class-conditional generator on Olivetti faces with no retraining and no learned classifier. On MNIST digit images, stochastic attention produced samples that were markedly more novel and more diverse than the best learned baseline while matching a Metropolis-corrected gold standard. On protein sequences from a small Pfam family, the generation regime preserved amino acid composition far more faithfully than a variational autoencoder at matched novelty, indicating that the training-free score function retained family-level fidelity that learned models lost. A denoising diffusion baseline failed across all memory sizes tested, producing samples indistinguishable from isotropic noise. The approach required no architectural changes to the underlying attention mechanism.

Figures & tables

Appendix figures & tables29 assets

Supplementary material from the paper’s appendix.

Appendix

Explore similar work

CardsList
  1. Training-Free Generation of Protein Sequences from Small Family Alignments via Stochastic Attention

    Mar 16, 2026Jeffrey D. VarnerHopfield NetworksMolecular Generation

  2. Conditioning Protein Generation via Hopfield Pattern Multiplicity

    Mar 20, 2026Jeffrey D. VarnerConditional Generative ModelingConditional Generation

  3. Attention-Based Sampler for Diffusion Language Models

    Mar 18, 2026Yuyan Zhou, Kai Syun Hou, Weiyu Chen +1Diffusion SamplingDiffusion Language Model Decoding