alphaFeedback

WorksComputer Science

Sample-efficient learning with Dense Associative Memories

AI contributions
  • ChatGPT 5.5/6 Pro
  • Codex
View details

Abstract

We analytically study the evolution of the energy function of Dense Associative Memories (DenseAMs) as they train on randomly sampled codewords of random expander low-density parity-check codes (a.k.a. solutions of random XORSAT problems). We identify two distinct regimes and a transition between them, reminiscent of grokking in neural networks. A regime of small training set size is where the model memorizes a few training examples but cannot discover the underlying rules of the entire codeword dictionary generative process. The opposite regime, corresponding to a larger training set size, is where the model has uncovered the sparse constraints that generated the entire data set after seeing only polynomially many patterns. We also design a novel class of DenseAMs with a thresholding learning rule, and show that any amount of thresholding enables the model to perform simplified sparse Hamiltonian learning, which exponentially reduces the number of training examples needed to learn the true underlying data set. In this regime, the model learns how to discover exp⁡[O(n)]\exp[\mathrm{O}(n)] solutions from only O(log⁡n)\mathrm{O}(\log n) training samples, which is asymptotically optimal for any learning algorithm. When training on codewords of certain random codes, the model can even learn the underlying code when a small O(1) fraction of bits are latent variables. These latent variables are not shown to the model during learning, but will be discovered by sparsifying observed higher-order correlations. For certain random codes, we show that a simple and conservative algorithm learns a minimal latent representation for the data set. This provides a transparent, physics-motivated, and analytically tractable toy model for how deep latent representations emerge in an associative memory training.

Introduction

A memorization-to-generalization transition is a hallmark of modern AI models. At early stages of training, large models typically memorize individual instances of training data. As training progresses, the models discover more abstract features and transition from relying on example-specific details to forming reusable knowledge via internal representations. This phenomenon has received substantial attention in Large Language Models, where it is typically called “grokking” [1, 2, 3, 4, 5]. Similar observations have been made in Diffusion Models [6, 7, 8, 9], and Dense Associative Memories (DenseAMs) [8]. Interest in this phenomenon is motivated both by practical concerns – including privacy and copyright infringement arising from the memorization of training data – and by a more fundamental question: how do individual training examples turn into generalizable knowledge encoded in a model’s weights?

Although the notion of a memorization-to-generalization transition is intuitive and widely used, it remains difficult to characterize rigorously in the context of natural datasets. The underlying rules governing natural datasets are generally unknown. Consequently, there is no canonical criterion for determining when a model has transitioned from memorizing individual training examples to learning the underlying data-generating structure. This ambiguity also makes the transition difficult to quantify as a function of the training set size.

In this paper we study this problem in a simplified setting where precise results can be found. Specifically, we study how DenseAMs learn random instances of the XORSAT problem; equivalently, how they learn low-density parity-check codes over binary variables. DenseAMs are a prominent class of energy-based models, which have super-linear (in the size of the neural network) memory storage capacity [10]. They generalize the Hopfield network of associative memory, which has a linear memory storage capacity [11]. The generic feature of this class of models is that they have a very large number of basins of attraction (possibly exponentially large in the size of the network), and, at the same time, each basin has a substantial volume. The latter property makes if possible to perform error correction by following a trajectory of the dynamical system minimizing the energy of DenseAM. To set up the problem, we sample a small number of random codewords from expander low-density parity-check (LDPC) codes [12, 13] to form the training set, and ask how many samples are needed until the DenseAM learns the underlying parity-checks (constraints) of the code, rather than simply memorizing individual instances from the training set. In other words, how many training samples are needed for DenseAM to recover the true underlying generative process of the LDPC codewords?

An LDPC code is a standard method for protecting digital information from errors during transmission or storage. When transmitting a string of bits, an LDPC code adds a finite fraction of redundant bits: the role of these redundant bits is to act as parity-checks on the original bits that encoded the logical information. The code is “low-density” when each bit is involved in only a finite-number of (small) parity-checks, and in turn each small check is a constraint involving only a finite number of bits. If some bits are corrupted by noise, the receiver can use the pattern of satisfied and violated checks to infer which bits are most likely incorrect. For random LDPC codes, this procedure works with high probability when a small O(1)O(1) fraction of the bits are corrupted.

The beauty of LDPC codes is that their codewords form a nice algorithmic dataset – every codeword comes from a clearly defined mathematical process: in this case, finding solutions to linear equations over F2\mathrm{F}_2, a.k.a. the integers (mod 2). This creates an opportunity for training an AI model on a small subset of codewords (the training set), and test the model on the remaining codewords (the test set) without ever revealing the underlying mathematical process of code word generation. Obviously, we can test whether the AI has learned the underlying LDPC code by checking whether or not all of the unseen codewords are verified as solutions by the AI.

As we will show, DenseAM is a perfect model to train on random LDPC codewords. The model is defined by an energy function, which has a huge (possibly exponential in the size of the network) number of local minima. Inference dynamics corresponds to a temporal evolution of a dynamical system decreasing the energy, and the low-energy states correspond to plausible data-points. The appealing aspect of DenseAMs is that it is possible to train them both via a self-supervised learning via the backpropagation algorithm [14], and, at the same time, via simpler Hebbian-style learning rules [10]. The latter eliminates the complexity of training process from the main phenomenon that we focus on in this work: how sample complexity of the data drives the memorization-to-generalization transition. For this reason we adopt DenseAMs as a toy model laboratory for studying this phenomenon.

In fact, the architecture of off-the-shelf DenseAM is more or less perfectly suited for the efficient learning of XORSAT. The reason is that under Hebbian learning, the real parity-checks of the code correspond to weights in the energy function that are maintained as large during training, while false parity-checks are equally likely to be obeyed or violated. Therefore under Hebbian learning, DenseAM learns to reduce the weight on false parity-checks until eventually, the energy landscape is dominated by the true parity-checks. Far past this point (with increasing training set size), the inference dynamics described in the previous paragraph amounts to gradient descent in the underlying Hamiltonian, where each codeword is a local minimum with a large energy basin around it. Even better, we may read off the underlying rules by identifying the large weights in the learned energy function. We can, therefore, quantitatively assess exactly how long it takes for DenseAM to learn the underlying code.

Our results are foreshadowed by earlier literature. For example, a long time ago, Valiant proposed a PAC theory of approximately-learnable problems, with satisfiability problems (which include XORSAT) as a prime application [15]. More recently, a systematic theory of sparse Hamiltonian learning [16, 17, 18, 19] has been developed, where it is a well-known result that only O(log⁡n)O(\log n) samples are necessary to learn a Hamiltonian when observing random samples drawn from its Gibbs state. The Hamiltonian itself will typically have poly⁡(n)\operatorname{poly}(n) terms, and its Gibbs state may cluster around exp⁡[O(n)]\exp[O(n)] local minima, as in a typical spin glass or complex system [20]; these features do not make learning the Hamiltonian itself parametrically harder! The key point is that sparse learning is capable of using the same samples to independently discover many different low-order correlations corresponding to different interactions in the Hamiltonian.

The difference between sparse learning and the Hebbian learning rule of DenseAM is that the latter is a computationally efficient algorithm, without an all-purpose guarantee that it learns the correct problem. Of particular note is that sparse learning is increasingly slow when the temperature of the sampled Gibbs state is very low. It turns out, however, that XORSAT is a very special “sparse Hamiltonian” to learn – even at zero temperature (the limit of interest for our algorithmic dataset) we may still exactly learn the Hamiltonian. To achieve the optimal O(log⁡n)O(\log n) scaling of the training set size predicted by sparse learning, we will add a thresholding rule to Hebbian learning, where suitably small couplings are, roughly, rounded down to zero. We will prove that this modification to DenseAM causes an exponential increase in the efficiency of learning. Related ideas appeared in [21, 22], where the authors wished to mock the distribution of solutions to a satisfiability problem, rather than learn it exactly.

With or without thresholding, we can quantitatively describe the resulting memorization-to-generalization transition undergone by DenseAM as a function of training set size. In the limit of high thresholding, there is a transition between memorization and generalization, reminiscent of the reverse code engineering problem from classical LDPC codes [23, 24]. We prove that this transition is surprisingly sharp: with a sufficiently small O(log⁡n)O(\log n) number of training examples, DenseAM will literally only be able to memorize the seen examples (and their linear combinations); with only an O(1)O(1) factor of extra patterns, it learns the entire code. In the limit of no thresholding, there is a simple transition as well. After seeing few patterns, the energy landscape of DenseAM looks Hopfield-like [10, 11] and is dominated by the observed patterns. After seeing sufficiently many [poly⁡(n)][\operatorname{poly}(n)] patterns, the weights of the true parity-checks in the Hamiltonian dominate over the random noisy couplings dominated by the training set, and correspondingly the energy landscape increasingly matches XORSAT (as the learned energy function becomes the XORSAT Hamiltonian exactly).

Finally, we show that this optimal performance of DenseAM in learning XORSAT persists when a small fraction of the bits in XORSAT are not shown to the AI – they are latent. Again, the simplifying structure of XORSAT makes it possible for us to very efficiently learn the underlying latent variables, analogous to sparse latent learning [25, 26].

Basics of Dense Associative Memory

We are studying models where the patterns to learn are bitstrings of length nn. We denote each pattern as an nn-component vector (ξ1μ,…,ξnμ)(\xi_1^\mu,\ldots,\xi_n^\mu) where each ξiμ∈{±1}\xi_i^\mu\in\{\pm1\}. Here and in what follows, the indices i,j,…∈{1,…,n}i,j,\ldots\in\{1,\ldots,n\} denote the bits, while μ,ν,…\mu,\nu,\ldots denote the patterns that we will feed the architecture. We will choose patterns ξμ∈C\xi^\mu\in\mathcal{C} randomly out of some subset C⊆{±1}n\mathcal{C} \subseteq\{\pm1\}^n. Our goal will be to learn an energy function E^:{±1}N→R\hat{E} : \{\pm1\}^N \to\mathbb{R}, such that every element of C\mathcal{C} is a local minimum of E^\hat{E}.

A simple proposal is to choose E^\hat{E} as an mm-local DenseAM [10]:

E^(σ)=−1P∑μ=1P(∑i=1nξiμσi)m.(1)\hat{E}(\sigma)=-\frac{1}{P}\sum_{\mu=1}^{P}\left(\sum_{i=1}^{n}\xi_i^\mu\sigma_i\right)^m. \tag*{(1)}

It is convenient to introduce tensor

Ti1⋯im:=1P∑μ=1Pξi1μ⋯ξimμ.(2)T_{i_1\cdots i_m}:=\frac{1}{P}\sum_{\mu=1}^{P}\xi_{i_1}^\mu\cdots\xi_{i_m}^\mu. \tag*{(2)}

and its thresholded version

T^i1⋯im=ϕa(Ti1⋯im),(3)\hat{T}_{i_1\cdots i_m}=\phi_a(T_{i_1\cdots i_m}), \tag*{(3)}

where

ϕa(x):=11−asign⁡(x)max⁡(0,∣x∣−a).(4)\phi_a(x):=\frac{1}{1-a}\operatorname{sign}(x)\max(0,|x|-a). \tag*{(4)}

For later purposes, we also write

E^(σ)=−∑i1,…,imT^i1⋯imσi1⋯σim,(5)\hat{E}(\sigma)=-\sum_{i_1,\ldots,i_m}\hat{T}_{i_1\cdots i_m}\sigma_{i_1}\cdots\sigma_{i_m}, \tag*{(5)}

where the sum over indices i1,…,imi_1,\ldots,i_m allows repeated entries. In the classical DenseAM (1), we have a=0a=0:

T^i1⋯im=ϕa=0(Ti1⋯im)=1P∑μ=1Pξi1μ⋯ξimμ.(6)\hat{T}_{i_1\cdots i_m}=\phi_{a=0}(T_{i_1\cdots i_m})=\frac{1}{P}\sum_{\mu=1}^{P}\xi_{i_1}^\mu\cdots\xi_{i_m}^\mu. \tag*{(6)}

As we will see later, it is also interesting to consider a thresholded DenseAM (TDenseAM), where parameter 0≤a<10\leq a<1. The role of the parameter aa is to provide a “noise floor” below which we reject couplings in E^\hat{E}. In other words, we wish to only keep terms in E^\hat{E} where we see a persistent signal across the observed patterns.

Once we have a learned energy function E^\hat{E}, we simply perform gradient descent from any initial condition to deduce the output of the model, as is standard in the literature on EBMs. In practice, we will perform gradient descent by choosing each bit (in a random order), and flipping it if doing so lowers the energy. We update the value of EE before checking the next bit. This algorithm terminates in a local minimum after a finite number of steps [27].

LDPC codes

Whether or not the DenseAM can efficiently learn will clearly depend on the choice C\mathcal{C} of patterns. A natural idea is to choose C\mathcal{C} as the ground states of a frustration-free energy function EE, which itself takes the form of

E(σ):=−∑i1,…,imJi1⋯imσi1⋯σim.(7)E(\sigma) := - \sum_{i_1,\ldots,i_m} J_{i_1\cdots i_m}\sigma_{i_1}\cdots\sigma_{i_m}. \tag*{(7)}

Then we would want to learn T^i1⋯im=Ji1⋯im\widehat{T}_{i_1\cdots i_m}=J_{i_1\cdots i_m}. There’s a natural way to choose such Ji1⋯imJ_{i_1\cdots i_m}. If EE is frustration-free, we need, for every σ∈C\sigma\in C, Ji1⋯imσi1⋯σim≥0J_{i_1\cdots i_m}\sigma_{i_1}\cdots\sigma_{i_m} \ge0. For simplicity, suppose each Ji1⋯im≥0J_{i_1\cdots i_m} \ge0. Then we need σi1⋯σim=1\sigma_{i_1}\cdots\sigma_{i_m}=1 for any Ji1⋯im>0J_{i_1\cdots i_m}>0. This is precisely the XORSAT problem in computer science, also known as a low-density parity-check (LDPC) code [13].

It is more natural to switch to a binary representation:

ξiμ:=1−2biμ,(8)\xi_i^\mu:= 1 - 2b_i^\mu, \tag*{(8)}
σi:=1−2xi.(9)\sigma_i := 1 - 2x_i. \tag*{(9)}

The ground states of EE, or the elements of CC, are then the right null vectors of a parity-check matrix HH:

C={b∈F2n:Hb=0},(10)C = \{b \in\mathbb{F}_2^n : Hb = 0\}, \tag*{(10)}

where F2={0,1}\mathbb{F}_2 = \{0,1\} and the parity-check matrix HH is F2\mathbb{F}_2-valued. For every Ji1⋯im≠0J_{i_1\cdots i_m}\ne0, we can add a row α\alpha to the parity-check matrix with

Hαi={1i∈α={i1,…,im}0i∉α.(11)H_{\alpha i} = \begin{cases} 1 & i \in\alpha= \{i_1,\ldots,i_m\} \\ 0 & i \notin\alpha \end{cases}. \tag*{(11)}

By construction, notice that CC has the structure of a vector space. The dimension of this vector space is labeled kk, and referred to as the number of logical bits. Clearly then, ∣C∣=2k|C|=2^k. In what follows, let

ΔB:={1ΔB is even0ΔB is odd.(12)\Delta_{\mathrm{B}} := \begin{cases} 1 & \Delta_{\mathrm{B}}\text{ is even} \\ 0 & \Delta_{\mathrm{B}}\text{ is odd} \end{cases}. \tag*{(12)}

References

  1. [1]Alethea Power, Yuri Burda, Harri Edwards, Igor Babuschkin, and Vedant Misra, “Grokking: Generalization beyond overfitting on small algorithmic datasets,” arXiv preprint arXiv:2201.02177 (2022).arxiv.org/abs/2201.02177
  2. [2]Andrey Gromov, “Grokking modular arithmetic,” (2023), arXiv:2301.02679 [cs.LG].arxiv.org/abs/2301.02679
  3. [3]Mohamad Amin Mohamadi, Zhiyuan Li, Lei Wu, and Danica J. Sutherland, “Why do you grok? A theoretical analysis on grokking modular addition,” in Proceedings of the 41st International Conference on Machine Learning, edited by Ruslan Salakhutdinov, Zico Kolter, Katherine Heller, Adrian Weller, Nuria Oliver, Jonathan Scarlett, and Felix Berkenkamp (PMLR, 2024) pp. 35934–35967.
  4. [4]John X Morris, Chawin Sitawarin, Chuan Guo, Narine Kokhlikyan, G Edward Suh, Alexander M Rush, Kamalika Chaudhuri, and Saeed Mahloujifar, “How much do language models memorize?” arXiv preprint arXiv:2505.24832 (2025).arxiv.org/abs/2505.24832
  5. [5]Ziyue Li, Chenrui Fan, and Tianyi Zhou, “Grokking in llm pretraining? monitor memorization-to-generalization without test,” in International Conference on Learning Representations, Vol. 2026 (2026) pp. 89561–89583.
  6. [6]Gowthami Somepalli, Vasu Singla, Micah Goldblum, Jonas Geiping, and Tom Goldstein, “Diffusion art or digital forgery? investigating data replication in diffusion models,” in 2023 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (IEEE, 2023) pp. 6048–6058.arxiv.org/abs/2212.03860
  7. [7]Nicolas Carlini, Jamie Hayes, Milad Nasr, Matthew Jagielski, Vikash Sehwag, Florian Tramer, Borja Balle, Daphne Ippolito, and Eric Wallace, “Extracting training data from diffusion models,” in 32nd USENIX security symposium (USENIX Security 23) (2023) pp. 5253–5270.arxiv.org/abs/2301.13188
  8. [8]Bao Pham, Gabriel Raya, Matteo Negri, Mohammed J Zaki, Luca Ambrogioni, and Dmitry Krotov, “Memorization to generalization: Emergence of diffusion models from associative memory,” arXiv preprint arXiv:2505.21777 (2025).
  9. [9]Tony Bonnaire, Raphaël Urfin, Giulio Biroli, and Marc Mézard, “Why diffusion models don’t memorize: The role of implicit dynamical regularization in training,” Advances in Neural Information Processing Systems 38, 141266–141286 (2026).
  10. [10]Dmitry Krotov and John J Hopfield, “Dense associative memory for pattern recognition,” Proc. NeurIPS 30, 1180 (2016).arxiv.org/abs/1606.01164
  11. [11]John J. Hopfield, “Neural networks and physical systems with emergent collective computational abilities,” Proc. Natl. Acad. Sci. 79, 2554–2558 (1982).
  12. [12]Michael Sipser and Daniel A. Spielman, “Expander codes,” IEEE Transactions on Information Theory 42, 1710–1722 (1996).
  13. [13]T. Richardson and R. Urbanke, Modern Coding Theory (Cambridge University Press, 2008).DOI
  14. [14]Dmitry Krotov and John Hopfield, “Dense associative memory is robust to adversarial inputs,” Neural computation 30, 3151–3167 (2018).DOI
  15. [15]L. G. Valiant, “A theory of the learnable,” Communications of the ACM 27, 1134 (1984).
  16. [16]Pradeep Ravikumar, Martin J. Wainwright, and John D. Lafferty, “High-dimensional Ising model selection using ℓ₁-regularized logistic regression,” The Annals of Statistics 38, 1287–1319 (2010), arXiv:0804.4202.arxiv.org/abs/0804.4202
  17. [17]Guy Bresler, “Efficiently learning Ising models on arbitrary graphs,” in Proceedings of the Forty-Seventh Annual ACM Symposium on Theory of Computing, STOC ’15 (Association for Computing Machinery, 2015) pp. 771–782, arXiv:1411.6156.arxiv.org/abs/1411.6156
  18. [18]Marc Vuffray, Sidhant Misra, Andrey Y. Lokhov, and Michael Chertkov, “Interaction screening: Efficient and sample-optimal learning of Ising models,” in Advances in Neural Information Processing Systems, Vol. 29 (Curran Associates, Inc., 2016) pp. 2595–2603, arXiv:1605.07252.arxiv.org/abs/1605.07252
  19. [19]Adam R. Klivans and Raghu Meka, “Learning graphical models using multiplicative weights,” in 2017 IEEE 58th Annual Symposium on Foundations of Computer Science (FOCS) (IEEE, 2017) pp. 343–354, arXiv:1706.06274.arxiv.org/abs/1706.06274
  20. [20]Marc Mézard and Andrea Montanari, Information, Physics, and Computation (Oxford University Press, Oxford, 2009).DOI
  21. [21]Anindya De, Ilias Diakonikolas, and Rocco A. Servedio, “Inverse problems in approximate uniform generation,” Electronic Colloquium on Computational Complexity 19, 152 (2012), eCCC Report TR12-152, arXiv:1211.1722.arxiv.org/abs/1211.1722
  22. [22]Anindya De, Ilias Diakonikolas, and Rocco A. Servedio, “Learning from satisfying assignments,” in Proceedings of the Twenty-Sixth Annual ACM-SIAM Symposium on Discrete Algorithms, SODA ’15 (Society for Industrial and Applied Mathematics, 2015) pp. 478–497.DOI
  23. [23]M. Cluzeau and J-P. Tillich, “On the code reverse engineering problem,” in Proc. IEEE. Int. Symp. Inf. Th. 2008 (2008) p. 634.DOI
  24. [24]T. Kaufman and M. Sudan, “Sparse random linear codes are locally decodable and testable,” Proc. FOCS 48, 590 (2007).
  25. [25]Guy Bresler, Frederic Koehler, and Ankur Moitra, “Learning restricted Boltzmann machines via influence maximization,” in Proceedings of the 51st Annual ACM SIGACT Symposium on Theory of Computing, STOC ’19 (Association for Computing Machinery, 2019) pp. 828–839, arXiv:1805.10262.arxiv.org/abs/1805.10262
  26. [26]Guy Bresler and Rares-Darius Buhai, “Learning restricted Boltzmann machines with sparse latent variables,” in Advances in Neural Information Processing Systems, Vol. 33 (Curran Associates, Inc., 2020) arXiv:2006.04166 [cs.LG].arxiv.org/abs/2006.04166
  27. [27]Dmitry Krotov, Benjamin Hoover, Parikshit Ram, and Bao Pham, “Modern methods in associative memory,” arXiv preprint arXiv:2507.06211 (2025).arxiv.org/abs/2507.06211
  28. [28]Véronique Gayrard, “Mixed memories in Hopfield networks,” arXiv:2504.04879.arxiv.org/abs/2504.04879
  29. [29]A. Lucas, “Learning modular addition as a latent SAT problem,” (unpublished).
  30. [30]B. Bollobás, Random Graphs, 2nd ed. (Cambridge University Press, 2001).
  31. [31]A. Békéssy, P. Békéssy, and J. Komlós, “Asymptotic enumeration of regular matrices,” Studia Sci. Math. Hungar. 7, 343 (1972).
  32. [32]W. C. S. Suen, “A correlation inequality and a poisson limit theorem for nonoverlapping balanced subgraphs of a random graph,” Random Struct. Alg. 1, 231 (1990).DOI
  33. [33]S. Janson, “New versions of Suen’s correlation inequality,” Random Struct. Alg. 13, 467 (1998).doi.org/10.1002/(sici)1098-2418(199810/12)13:3/4<467::aid-rsa15>3.0.co;2-w
  34. [34]Yifan Hong, Jinkang Guo, and Andrew Lucas, “Quantum memory at nonzero temperature in a thermodynamically trivial system,” Nature Commun. 16, 316 (2025), arXiv:2403.10599 [quant-ph].DOI
  35. [35]Arun Kumar Kuchibhotla and Abhishek Chakrabortty, “Moving beyond sub-Gaussianity in high-dimensional statistics: applications in covariance estimation and linear regression,” Information and Inference 11, 1389–1456 (2022).DOI
  36. [36]Mariia Vladimirova, Stéphane Girard, Hien Nguyen, and Julyan Arbel, “Sub-Weibull distributions: Generalizing sub-Gaussian and sub-exponential properties to heavier tailed distributions,” Stat 9, 318 (2020).
  37. [37]M. Kearns and L. Valiant, “Cryptographic Limitations on Learning Boolean Formulae and Finite Automata,” J. ACM 41, 67 (1994).

Paper details

vlnc:W_rwqqdbp7
v1 · latestHistory (1)

published · Fresh — added to the Hub within the last 30 days

added ·

Usage

views · 8

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

CC BY 4.0

Original source

  • Computer Science

ChatGPT 5.5/6 Pro, Codex · View statement →

Looking for related papers…
Contents