arXiv:2610.22191cond-mat.dis-nnOct 2026

Manuscript Offprint

arXiv:2610.22191

Attention over noisy examples: generalization and memorization in the exponential Hopfield network

Francesco Alemanno

Abstract

In Hebbian learning from examples a Hopfield network of NN neurons is not supplied with the KK archetypes it has to retrieve but with MM blurred examples of each, of quality rr, and whether it can infer them depends on the load α=K/N\alpha = K/N (interference among them) and on the dataset entropy ρ=(1−r2)/(Mr2)\rho = (1 - r^2)/(Mr^2) (how little the examples say about them). We transfer this protocol to the exponential Hopfield model, whose zero-temperature update is a step of softmax attention with the unlabelled examples as keys. A signal-to-noise analysis gives in closed form the overlap between the output and an unseen archetype, m(1)=erf(1/2ρeff)m^{(1)} = \text{erf}(1/\sqrt{2\rho_{\text{eff}}}): the majority-rule law of the pairwise model at small load, with ρ\rho replaced by an attention entropy ρeff\rho_{\text{eff}} built from the weight the softmax gives to the correct class and the number of examples it spreads it over. Two consequences follow. First, in a window of inverse temperatures β\beta that widens as N\sqrt{N} the interference between archetypes is exponentially small in NβN\beta: the load drops out and the number of archetypes that can be learnt grows as exp⁡(cN)\exp(c\sqrt{N}). Second, learning fails differently: in the pairwise model through a spin-glass phase, in the exponential model through memorization: the softmax concentrates its weight on the training example closest to the input and returns it in place of the archetype. Seen from the input the softmax weights are those of the random energy model, and memorization is its freezing transition, at βN(1−r2)≃2ln⁡M\beta\sqrt{N(1 - r^2)} \simeq \sqrt{2\ln M}; it is measurable on a head whose keys are examples as the number of examples carrying weight. On MNIST the diagnostic follows the random-energy prediction; on fashion-MNIST it detects sub-clusters in the classes, and the best accuracy lies beyond the memorization threshold, where the softmax reads out a local sub-prototype.

1 Introduction

Forty years after Hopfield’s model [1] and the statistical-mechanical theory of Amit, Gutfreund and Sompolinsky (AGS) [2, 3], Hebbian neural networks have returned to the centre of the machine-learning stage through two independent developments. On the one hand, dense associative memories [4, 5, 6] and their exponential limit [7, 8, 9] have shown that a Hebbian network with sufficiently steep interactions stores an exponential number of patterns, that the steepness of the interaction controls a transition from feature-like to prototype-like memories [4], and that one step of the zero-temperature dynamics of the exponential model is a softmax attention update with the stored patterns as keys and values [7, 11], a connection also read as a nearest-neighbour or kernel-smoothing view of attention [21, 22, 23]. On the other hand, the Hebbian prescription itself has been turned from a storage rule into a learning rule: in [12, 13] the network is supplied, instead of the archetypes ξμ\xi^{\mu}, with MM corrupted examples ημa\eta^{\mu a} of each of them, and the Hebbian coupling is built on the examples, without labels (unsupervised, [12]) or with the examples averaged class by class (supervised, [13]); the same protocol has been solved for dense pp-body networks in [14, 15], where the load becomes αp=K/Np−1\alpha_p = K/N^{p-1} (see also [16, 17, 18]). The resulting phase diagram is controlled by the AGS load α=K/N\alpha = K/N and by a new parameter, the dataset entropy ρ=(1−r2)/(Mr2)\rho = (1 - r^2)/(Mr^2), with rr the quality of the examples; archetypes are retrieved although they were never presented, provided ρ\rho is small enough and α\alpha lies below a ρ\rho-dependent critical load. Two sources of noise limit the retrieval: the finite number and quality of the examples, measured by ρ\rho, and the interference of the other stored patterns on the field acting on each neuron, usually called crosstalk, which grows with the load α\alpha. When either is too large the network enters a spin-glass phase, in which its states are correlated with none of the archetypes: in the learning setting this phase is the thermodynamic signature of overfitting.

The present work merges the two lines. We ask what happens to the (α,ρ)(\alpha, \rho) phase diagram when the examples themselves become the stored keys of the exponential Hopfield model, that is, of an attention layer, with no use of the labels. Three questions are addressed: (i) whether a layer of attention, operating on a dataset of noisy examples, generalizes to the unseen archetypes and in which range of the inverse temperature β\beta of the softmax; (ii) what is the fate of the load α\alpha, which in the pairwise model bounds the number of archetypes that can be learnt; (iii) whether the spin-glass phase has a counterpart in the exponential model, i.e., what overfitting looks like when the network is a transformer layer rather than a Hopfield network.

The answers are obtained analytically by a signal-to-noise analysis, which in the present setting can be carried out in closed form, and are checked by Monte Carlo simulations. In a nutshell: in [13] the probability of reconstructing a pixel of the archetype by a majority vote over its MM examples is 12[1+erf(1/2ρ)]\frac{1}{2}[1 + \mathrm{erf}(1/\sqrt{2\rho})], and the one-step magnetization of the network has the same error-function form; here we find that the one-step magnetization of an unseen archetype produced by an attention layer is again m(1)=erf(1/2ρeff)m^{(1)} = \mathrm{erf}(1/\sqrt{2\rho_{\mathrm{eff}}}), but the dataset entropy ρ\rho is replaced by an attention entropy ρeff(β)\rho_{\mathrm{eff}}(\beta) that depends on how the softmax distributes its weight over the training set. At intermediate β\beta the load drops out (ρeff→ρ(\rho_{\mathrm{eff}} \to \rho for any α)\alpha); at small β\beta the crosstalk of the pairwise model is recovered; at large β\beta the softmax condenses, i.e. it assigns essentially all of its weight to a single training example, and the layer memorizes. Seen from the query, the logits of the softmax are independent Gaussian variables, so that the attention layer is a random energy model (REM), the system of MM independent Gaussian energy levels introduced by Derrida [26, 27] as the simplest spin glass: the condensation is the freezing transition of that model, located at βN(1−r2)≃2ln⁡M\beta\sqrt{N(1-r^2)} \simeq \sqrt{2\ln M}, and it is the attention counterpart of the spin-glass phase. The window of generalization between the two edges widens with the system size as N\sqrt{N}. We then test the picture on MNIST and fashion-MNIST, and compare the Hebbian attention with a one-head attention classifier trained by gradient descent on the same datasets.

The present model is the p→∞p \to \infty end of the family of dense Hebbian networks learning from examples of [14, 15]: there the crosstalk is still extensive in the polynomial load αp\alpha_p, here it becomes logarithmic in KK, which is what allows the closed-form treatment. Related settings of learning from examples have been considered in [19] for dense p-body networks in the teacher-student scenario, in [20] for the random-features Hopfield model, and in [25] for hierarchical prototypes in polynomial dense memories. For the storage, rather than learning, properties of exponential models we refer to [6, 8, 9], and to [10] for the multilayer hetero-associative extension, whose exponential capacity and basins are obtained at β→∞\beta \to \infty by a large-deviation evaluation of the noise.