Manuscript Offprint
arXiv:2610.27384Sample-efficient learning with Dense Associative Memories
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Andrew Lucas and Dmitry Krotov
Department of Physics and Center for Theory of Quantum Matter,
University of Colorado, Boulder, CO 80309, USA
Dynamical Mind, Cambridge, MA 02141, USA
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 solutions from only 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 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.
Contents
1 Introduction 3
2 Basics of Dense Associative Memory 5
3 LDPC codes 6
4 Learning random codes 9
5 Discovering latent variables 13
6 Outlook 15
A Review of binary linear codes 16
A.1 Basic definitions 16
A.2 Useful properties 17
A.3 Random expander codes 18
B Learning random codes 24
B.1 How many training examples are needed? 24
B.2 Dynamics of learning: 26
B.3 Dynamics of learning: 35
C Learning latent variables 42
References 46
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 it 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) 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 , 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–19] has been developed, where it is a well-known result that only 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) terms, and its Gibbs state may cluster around 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( ) 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( ) number of training examples, DenseAM will literally only be able to memorize the seen examples (and their linear combinations); with only an 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)] 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].
2 Basics of Dense Associative Memory
We are studying models where the patterns to learn are bitstrings of length . We denote each pattern as an -component vector where each . Here and in what follows, the indices denote the bits, while denote the patterns that we will feed the architecture. We will choose patterns randomly out of some subset . Our goal will be to learn an energy function , such that every element of is a local minimum of .
A simple proposal is to choose as an m-local DenseAM [10]:
It is convenient to introduce tensor
and its thresholded version
where
For later purposes, we also write
where the sum over indices allows repeated entries. In the classical DenseAM (2.1), we have :
As we will see later, it is also interesting to consider a thresholded DenseAM (TDenseAM), where parameter . The role of the parameter is to provide a “noise floor” below which we reject couplings in . In other words, we wish to only keep terms in where we see a persistent signal across the observed patterns.
Once we have a learned energy function , 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 E before checking the next bit. This algorithm terminates in a local minimum after a finite number of steps [27].
3 LDPC codes
Whether or not the DenseAM can efficiently learn will clearly depend on the choice C of patterns. A natural idea is to choose C as the ground states of a frustration-free energy function E, which itself takes the form of
Then we would want to learn . There's a natural way to choose such . If is frustration-free, we need, for every , . For simplicity, suppose each . Then we need for any . 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:
The ground states of E, or the elements of C, are then the right null vectors of a parity-check matrix H:
where and the parity-check matrix is -valued. For every , we can add a row to the parity-check matrix with
By construction, notice that has the structure of a vector space. The dimension of this vector space is labeled , and referred to as the number of logical bits. Clearly then, . In what follows, let
In practice, we will prefer to pick a random matrix and choose accordingly. We choose the random matrix as follows [12]: pick a number , and choose the rows of randomly such that each row has exactly 1s and each column has exactly 1s. We now summarize some crucial properties of these random codes, leaving a more formal discussion to Appendix A. A useful representation of an LDPC code is a Tanner graph (or a factor graph), depicted in Figure 1. The Tanner graph contains nodes that are either bits or checks, with an edge between bit and check if and only if . LDPC codes then correspond to sparse Tanner graphs. We generate LDPC codes randomly by choosing random Tanner graphs where every bit node has degree and every
The precise distribution of such graphs that we sample (uniformly) from is detailed in Appendix A.

Figure 1: Illustration of a local patch of a Tanner graph of a random code with . Bits i are depicted as black circles; checks are depicted as orange squares. The number of small cycles in a Tanner graph is extremely small, so the graph will typically look locally tree-like.
check node has degree . Almost surely as ,
Relatedly, the number N of parity-checks of weight m is, with high probability,
There are simple, yet useful, observations about the typical weights . If is a real parity-check contained in , we always have
Otherwise, equally likely to be ; hence
Hoeffding's inequality implies
In fact, these observations explain why we should choose C as the codewords (ground states) of an LDPC code's . are chosen by (2.6) to be equal weight superpositions of the observed patterns. So in general, TDenseAM does not perform Hamiltonian learning; it simply measures low-order correlations between spins when drawing samples uniformly at random from C. We are only guaranteed that these low-order correlations exactly match the terms in E itself, which follows from the equations above, when E parametrizes a linear code. For this reason, the (T)DAM architecture is perfectly suited to learn binary linear codes. The suitability of the data set to the architecture will enable us to make rigorous statements about how the model learns.
4 Learning random codes
Now let us describe the learning process. Here we give an intuitive and non-rigorous discussion; all scaling arguments are established rigorously in Appendix B.
It is useful to first briefly review how the regular DenseAM (a = 0) architecture trains on random data [10]. Suppose that the number of patterns . When , (2.1) is dominated by the actual learned patterns, in the sense that there are deep energy wells surrounding every seen pattern . (There are also “mixed minima” corresponding to particular mixtures of patterns [28].) In contrast, once , the energy landscape becomes corrupted and overtrained.
The story changes when we train on random codewords of an LDPC code. Now the learned energy consists of two parts: the genuine parity-checks of the code, which contribute energy independent of the number of seen examples , along with “junk” pattern-sensitive terms, which contribute a typical energy ; these facts follow from (3.8) and (3.9b). If with , we see that the true parity-checks of the code begin to meaningfully shape the energy landscape: codewords are lower energy than random locations. However, this does not mean that DenseAM will successfully recover unseen codewords. Consider starting at an unseen codeword and perturbing the state by flipping any fraction of bits to align with a seen codeword. The net energy change is
where the first positive contribution counts the number of violated parity-checks, while the second negative contribution comes from the huge energy gain from pattern alignment in (2.1). Using (3.7), we see that until , the second term wins, so the DenseAM has a heavy bias towards reproducing seen patterns, just as when it is trained on random data. In fact, we prove when is larger than a suitable O(1) constant, there are (with high probability) extensive energy barriers around each codeword. This ensures that the denseAM will not simply return a seen pattern – it will at worst give an approximation of the true codeword (with a bounded fraction of errors) when initialized on an arbitrary codeword.
Next, let us turn to the opposite regime of . This extreme thresholding limit is equivalent to Valiant's (XOR)SAT learning algorithm [15], and to the “reverse code engineering” problem [23, 24]. For simplicity in the discussion that follows, let us assume that the first shown pattern is (we can always “gauge fix” the training data so that this occurs). After the first pattern, TDenseAM will presume that if is odd, every spin must be fixed to ; if is even, is also allowed. TDenseAM presumes that a parity-check is valid if and only if it has never seen it violated, and at this first step it has learned checks. All but of them are spurious and should be unlearned during training. As in (3.9a), each subsequent shown random codeword has a 50% chance of violating each remaining spurious check. The number of parity-checks in thus scales as and concentrates around this mean in the thermodynamic limit.
Denote as the learned parity-check matrix after P patterns. contains checks of weight m, m - 2, etc. Further denote
The number of minima of is , because consists only of the parity-checks consistent with all seen codewords. Since the minima of correspond to solutions of a linear equation, superpositions of observed codewords are also valid solutions.
We conjecture that there is a sharp transition near
Indeed, we can show that once , the number of spurious checks scales subextensively with n. Even if all of these spurious checks are linearly independent (and they will be with high probability), they can at most reduce the rank to
the first term while once for any , the second term is subextensive.
The behavior for depends on the value of . For , we find that for . This is because every LDPC code with weight-2 checks corresponds to a set of decoupled repetition codes: namely, there will be independent clusters of spins that must all agree within each cluster. We need only observe codewords where any pair of two repetition code blocks take different values in order to distinguish them. For example, we can see patterns 0000, 0011, 0101 to learn that these 4 bits are all independent.
In contrast, for , we instead expect that
until . The reason for this drastic change in behavior is simple, yet profound: with higher weight checks, the surviving spurious checks necessarily have many linear dependencies (i.e. redundancies) until . These dependencies are also more complex compared to : checks and can be violated by the next codeword while is a combination of non-violated checks. We can crudely estimate that the typical number of ways

Figure 2: as a function of when training the TDenseAM on random bitstrings of length . The bubble plot depicts the probability of seeing a given value of at each when choosing a random sequence of training data. Left: . Right: , where (4.5) is clearly visible at small .
to express as a linear combination of non-violated checks scales as . Hence when (with ), removing and only increases by 1. With a little more work, we can prove (4.5) as long as . (4.5) is related to the fact that most random codes generated by picking random bitstrings as codewords are LDPC [24]; it is then natural that a similar fact such as (4.5) can persist when given random codewords. It may be a little surprising, though, that the structure of the code reveals itself so rapidly!
The dramatic change in learnability of the LDPC code is very easy to see when training a weight-m TDenseAM on random bitstrings. As , the TDenseAM should eventually learn , or . The random trajectories of behave very differently when vs. , exactly as predicted above. A small numerical demonstration is shown in Figure 2.
The punchline is that when , TDenseAM learns “slowly” at small , and largely by memorization. Indeed, for the learner, linear combinations of seen patterns are necessarily minima, so learning is the least efficient possible, as long as every new seen pattern is linearly independent of the others (which almost surely happens as ). At a critical , the spurious checks abruptly fall “below” the noise threshold, and TDenseAM begins to rapidly generalize beyond the training data it has seen.
This behavior is reminiscent of the grokking phenomenon seen in neural networks [1–5]: one trains a neural network on “algorithmic datasets” such as ours, and observes that first the neural network learns to reproduce training data it has seen, only “discovering” the underlying rules generating the data long after reproducing training data. In neural networks, one could either talk about such a transition upon showing more training data, or optimizing network weights on a fixed dataset; in our context, only the former makes sense. In the context of our XORSAT problem, the TDenseAM is basically guaranteed by construction to always correctly reproduce training data it has already seen. The non-trivial step in the analogue “grokking” is to generalize, which in this context amounts to correctly assigning unseen codewords (solutions) to local minima in . Figure 2 demonstrates our analogue of this “grokking” phenomenon in the TDenseAM when trained on random data. In our context, the fact that grokking is a manifestation of the need to suppress spurious couplings in is very clear. Firstly, it takes a long time for the spurious checks in to be suppressed relative to the true checks. The abruptness of the transition is, in some sense, simply an artifact of the slow rate at which TDenseAM learns to remove spurious checks. Secondly, once the spurious contribution to is comparable to the true one, removing half of the spurious checks in each step leads to an explosive growth in generalizability, with nearly the entire code being discovered in a short training window.
When , we expect a rough “interpolation” between the two extreme limits above. From (3.10), TDenseAM will almost surely learn the code so long as
This follows directly from a sub-optimal tail bound estimate on the probability of seeing a finite fraction of codewords that violate (or not) any spurious check. So, any amount of thresholding at all immediately leads to complete discovery of the underlying code – and all of its codewords – in patterns.
We directly test this transition numerically by studying the behavior of the TDenseAM when it is initialized in an unseen codeword . Suppose that after initializing and running gradient descent using , the final bit string is . To test whether or not TDenseAM has simply memorized the patterns it has already seen, we probe
Here denotes Hamming distance, or the number of bits in different states. In the case where is even, we must also minimize over as the TDenseAM will always have a global spin flip symmetry. thus represents the fraction of bits in a “new configuration” relative to any trained pattern: should be 0 if we are memorizing, and if we are discovering new codewords. Since we have fed the TDenseAM an actual codeword, we can test whether it has learned by asking whether or not the initial state was in fact a local minimum, which is conveniently measured by the fraction of flipped spins:
Figure 3 shows the behavior of and as a function of P. When , we see a long period of strict memorization – just like in the DenseAM, we are overwhelmingly likely to simply reproduce a seen training example as the energy landscape is overwhelmingly shaped by these seen examples. (Occasionally we do see the model settle at an unseen point, but this is rare.) At a scale smaller than our bound in (4.6), TDenseAM begins to efficiently generalize: develops

Figure 3: The memorization-generalization transition as a function of P, after initializing TDenseAM at unseen codewords. The probability distributions of and are depicted as bubble plots. Training is done on a code . Left: . Right: .
local minima appear near typical unseen codewords, so it has learned the rules generating the data set. The transition from memorization to generalization appears relatively sharp, but we have not analytically characterized this transition, and our simulations are clearly limited by finite-size effects. The transition is clearly much more efficient when . In this case, is appreciable already at P = 2, which is easily understood: TDenseAM in this limit also learns linear combinations of seen codewords.
It is plausible that right at the memorization-generalization transition, at any , TDenseAM becomes very “corrupted” by a glassy energy landscape in . This occurs in Figure 3 during the regime when both and are sizable, right before generalization. This is likely due to the glassy energy landscape of random LDPC codes themselves. It would be interesting to investigate further in future work.
5 Discovering latent variables
It is often believed that when studying complex data patterns, some of the relevant degrees of freedom are not directly shown to the observer. Such bits are called latent. A potential example is that visible bits correspond to the pixels in an image, while latent bits describe what the image represents. There may not be a simple, local expression for without learning the latent variables.
Amazingly, we can also use TDenseAM to efficiently learn latent variables in XORSAT. Let the first bits be observed, and the remaining bits be latent. In this section, we will denote observed bits with ( ) and latent bits with ( ). We wish to generalize TDenseAM so that it can discover the latent bits. Importantly, TDenseAM will not be told how many latent bits there are, nor where latent bits may be relative to the observed interaction graph – it must discover all of this on its own.
A conservative way to discover a latent variable is to detect what we call an observable 3-shadow.
In the context of LDPC codes with weight-m checks, this shadow will take the form of three -weight observable checks with a special structure:
Here are vectors of Hamming weight . Notice that are consistent with three smaller, weight , checks that contain a latent variable :
The key intuition is that if we observe three such patterns, rather than only two, we have clear insight as to where the latent variable must go. If we only saw , but not , the decomposition into is not knowable. In principle, one could still introduce many candidate latent variables and keep only the ones which remain predictive. To keep the story simple, however, we will restrict to learn latent variables when they have a 3-shadow as above.
We now summarize how to build a latent TDenseAM, leaving details to Appendix C. The strategy is to run TDenseAM looking for weight- checks. We immediately accept checks of weight , but also look for observable 3-shadows among the observed variables. When we detect them, we introduce a latent variable to reduce them into acceptable checks with weight . The value of the latent variable should then be appended to all of the training data. Then, we re-run TDenseAM with the learned latent variables treated as observed. This process continues until we cannot discover any more latent variables. An illustration is given in Figure 4.
We prove in Appendix C that, almost surely as , latent TDenseAM can learn every latent variable correctly when training on random LDPC codes, if ,
for some O(1) constant , and the number of training patterns exceeds
In a nutshell, the proof uses the fact that locally, random codes look rather tree-like. This property of the code, more accurately called expansion, guarantees that some latent variables will always have observable 3-shadows, and that any time an observable 3-shadow is found, it comes from an actual latent variable. This also guarantees that latent TDenseAM will never introduce incorrect constraints.
The guarantee above does not rely on the latent bits being distributed randomly amongst the code; every subset of latent bits will be learned, as long as we have (5.3). This is interesting

Figure 4: Illustration of a local patch of a Tanner graph of a random code with observed (black) and latent (white) bits. The latent TDenseAM learner will detect since it has an observable 3-shadow. Learning reveals , which also subsequently has an observable 3-shadow.
because it means that we can even learn latent bits which are only observable after rounds of running TDenseAM. The correlations used to detect these deep latent variables will originally be extensive correlations among finite fractions of all of the observed bits. The expansion of random codes, along with the certification of the shallower latent bits, guarantees that the deepest latent variable is genuine and detectable.
6 Outlook
We have presented a simple and largely solvable model for how a (thresholded) dense associative memory learns on a specific algorithmic dataset – randomly chosen codewords of an expander LDPC code. This architecture first learns by memorization of observed patterns , and later abruptly begins to generalize well beyond the training data, in a sharp transition somewhat reminiscent of grokking. The same architecture is also capable of discovering latent variables efficiently, providing a simple and solvable cartoon for the role of deep latent variables as sparsifications of the rules that generated the dataset.
Although we have not explicitly verified it, it is almost certain that the models described here can easily train on corrupted LDPC codewords, and any thresholding ensures learnability in corrupted samples (so long as the corruption is reasonably independent); it would be interesting to study the dynamics of learning more carefully in this setting. More non-trivially, carefully chosen EBMs can provably efficiently learn other problems: for example, certain modular addition tables are discovered [29] doubly-exponentially faster in EBMs than in one-hot neural networks [1–5]. Perhaps the ideas we have fleshed out in a simplified setting may prove relevant more broadly in a theory of how AI learns structured data.
Acknowledgments
We thank MPI-PKS for hospitality as this work was initiated. ChatGPT 5.5/6 Pro was used to help write codes and to assist in proving the main theorems. Codex 5.5 Medium wrote the code to make figures on small sample sizes for the main text.
A Review of binary linear codes
A.1 Basic definitions
In the text that follows we will use some convenient shorthand: refers to the set of elements labeled by the first integers. Similarly we will just write to denote the set of all objects that could be labeled with : in particular, if denotes an -tuple of the bits which can be a coupling of the dense associative memory, then , etc. We denote the indicator function with
Lastly, we will sometimes refer to a vector interchangably with defined by . So the statement , and similar statements, should be understood in this light.
Consider a vector space over the two-element field , defined by addition and multiplication mod 2. The mod 2 will always be implicit when it is clear from context that operations are done over . A useful representation of will be given by the following proposition, which summarizes basic facts about linear algebra over finite fields:
Proposition A.1: Define a matrix such that
namely the rows of are linearly independent generators of . Then there exists a (non-unique) matrix with such that , and
We will denote and
Note that on , can be non-empty.
Definition A.2 (Canonical form): By Gaussian elimination we can always find a canonical form for the generator matrix G and parity-check matrix H:
Here is a matrix. Notice that a canonical form of need not be sparse, even if there exists a sparse representation of .
A.2 Useful properties
The following observation is crucial to our subsequent analysis:
Proposition A.3: Let . Define and
Then
Here is understood via the mapping (3.2).
Proof. Observe that
If , then for every , establishing the first line of our identity.
As for the second line, if then by definition there exists such that . For each in the sum (A.6), it is paired with a unique partner in the sum (since ), and . Summing over all such pairs of partners establishes the second line of (A.6).
Proposition A.4: Let be linearly independent non-trivial cosets in . Then there exist linearly independent codewords such that
Proof. First look for a such that . If such a did not exist, then contradicting our assumptions. Similarly, we construct candidate . If it was not possible to choose linearly independent , then there would exist some combination of which was orthogonal to every possible codeword, in violation of the assumption that the were independent. Once we have found linearly independent , we can do Gaussian elimination to find an invertible matrix such that .
A.3 Random expander codes
In this subsection, we will review established facts about random expander codes [13], emphasizing points which are relevant for our discussion. Its purpose is just to summarize the key properties of random codes which provide provable guarantees on efficient learning of TDenseAM for the remainder of the paper. The reader should feel free to only refer to this section as results are referenced below.
Definition A.5 (( , )-LDPC codes): A ( , )-LDPC code corresponds to parity-check matrix for which each row has Hamming weight and each column has Hamming weight . In other words, each bit connects to checks, and each check connects to bits. It is often useful to define a set of bits and checks ; in the previous discussion we had informally used . Given a subset of bits , we define its boundary
An analogous definition (with ) holds for the boundary of a check set.
It is actually quite easy to generate these codes randomly due to a clever algorithm known as the configuration model [30]: one simply generates random candidate codes and rejects them if they are “bad” – this will succeed with high probability after only a finite number of attempts, even as . We summarize the result without proof below:
Theorem A.6: Propose a -LDPC code by randomly connecting each bit to a check times, and stopping if the check has more than edges. The probability that there is at least one bit/check pair that are connected more than once is, as , at most [31].
We will use this simple generation algorithm below to prove some very useful facts about random LDPC codes. A key property about random codes is that they are expander codes, as defined below:
Definition A.7 (Left/right-expansion): A code has -left expansion if, for every set of bits with , . It has -right expansion if the analogous property holds for checks: . If both hold, the code has -expansion.
Proposition A.8 (Unique-neighbor expansion): Given a code with -expansion, consider any with . Let be the number of unique-neighbor checks which
Often, we will choose , because will be the natural order of interactions to learn in the dense associative memory!
connect only to a single bit in :
Then
Proof. The number of edges between bits in and checks in is given by . By Definition A.7, there are edges to checks. Comparing the total number of edges to the total number of edges to unique checks, vs. edges to non-unique checks, we see that
which implies (A.11).
☐
Corollary A.9: For any with , a code with expansion has
The code distance .
Proof. These are immediate consequences of Proposition A.8. Any check in must be violated, so (A.13) follows from (A.11). Since on any codeword, if either or .
Corollary A.10: In the setting of Proposition A.8, we are guaranteed that there exists with whenever
Proof. From (A.11), the average number of unique-neighbor checks in is . If , there must be at least one bit with . Hence we find (A.14).
The existence of useful codes is established by the following theorem, which we state without proof, although we do note that the bound on comes directly from the rank-nullity theorem on , and the techniques are similar to those discussed at the end of this subsection.
This is not an optimal bound, but it suffices for our conceptual purposes in this paper – namely, establishing that the code distance can be whenever we can establish expansion.
Theorem A.11: Take . Choose a -LDPC code uniformly at random via the configuration model (Theorem A.6). Then the code has a linear number of logical bits:
and with probability , the code is a -expander for any and any , where solves
with
Lastly, the following result tells us that the interaction graph of a random LDPC code does not contain very many interesting small subgraphs, with very high probability. In other words, random LDPC codes look locally tree-like.
Proposition A.12: Let be a bipartite graph with vertices and edges, with and O(1) constants. Pick a LDPC code uniformly at random, and let be the number of subgraphs isomorphic to . As , there exists a constant such that
In words, there are a finite number of short cycles in an LDPC code, and these cycles are all far from each other.
Proof. We can use Theorem A.6 to constrain the properties of a random LDPC code: suppose that a random pairing of bits and checks has property X with probability . Then, letting , the probability the event happens on an actual LDPC code must obey
meaning that
Now, in the configuration model, it is very easy to bound the probability of seeing a subgraph . If we demanded that the subgraph and was isomorphic to , this would occur with probability
Now enumerating over the total number of possible such subgraphs, we bound
for some . Combining (A.20) and (A.22) we obtain (A.18).
The remaining results in this section are a collection of scattered but useful facts about expander codes, which will be useful in establishing how TDenseAM trains on random codes.
Theorem A.13: Pick a LDPC code uniformly at random with . If there are checks, take and define
Then almost surely as , every vector obeys
for some O(1) constant . This property is known as check soundness.
Proof. Theorem A.11 shows that the dimension of the codespace is minimal – up to a sole redundant check when is even, all of the checks are independent. This redundancy is what requires us to look at the reduced weight in the even case.
The desired property follows immediately from Definition A.7 if , so we only need to consider the case where . Here, we follow the same strategy as the proof of Proposition A.12. Since , each bit sees one of its edges connected to a check in with probability no smaller than . Our goal is to bound the bare probability that exactly bits have an odd number of edges connecting to .
We can use the method of generating functions to bound this. Define the odd and even parts of the binomial distribution:
Then define
In the random generating model of Theorem A.6, we see that
(A.27)
Let ; note that . Notice that as ,
Observe that . Standard manipulations then reveal that
(A.29)
recalling the definition of in (A.17). We see that as ,
where
Choose any obeying . Combining (A.20) and (A.30), the probability of violating (A.24) vanishes exponentially as .
Corollary A.14: In a random LDPC code with , almost surely as , there are no non-zero elements of with Hamming weight smaller than . Moreover, the number of distinct weight checks is almost surely given by
Proof. By Theorem A.13, it suffices to look at small combinations of checks with , where we can then apply the expansion guarantee of Theorem A.11. For any , we know that . Since , we can choose arbitrarily close to . So if , the claim is established.
Thus let us discuss the case of , as follows analogously. Here we can apply Proposition A.12. For any , to find a check of weight smaller than , we would need to find a subgraph of the Tanner graph (Figure 1) isomorphic to two bits connected to checks, one check connected to the same bit times, etc.: any graph that contains independent cycles, namely has ; almost surely such a graph never appears. There are a finite number of such graphs to verify below a fixed number of checks (supplied by Theorem A.13), so the probability any one of them fails vanishes as by a union bound.
Finally, let us verify that the number of checks of weight is . We have at least checks by the construction of the code. Similar to the previous paragraph, we need at least a cycle of length 4 in the Tanner graph to find any redundant checks. Proposition A.12 shows that the expected number of such cycles is ; applying Markov's inequality completes the proof.
Corollary A.15: In a random LDPC code with parity-check matrix and , almost surely as ,
for any r.
Proof. Again, Theorem A.11 and Theorem A.13 imply we need only worry about combinations of O(1) checks when , as the code is an expander code. We then apply Proposition A.12. Suppose we have a candidate subgraph of the Tanner graph containing checks in set , where we include every edge (and corresponding bit ) in the subgraph. If this set of checks gave us a word of weight in , we would have at most – this would be the case if all bits in the word have degree 1, and all other bits in the subgraph have degree 2. Then we have
By Markov’s inequality (as ), with probability at least , we see any candidate subgraph with a fixed number of checks at most times. Since there are a finite number of candidate graphs to consider, we deduce that almost surely (A.33) holds.
Corollary A.16: In the setting of Corollary A.15, a random codeword has Hamming weight close to :
Proof. Almost surely there are no checks of weight ≤ 2. Use the ±1-valued and evaluate
Proposition A.3 shows that
because the only elements in are the trivial vectors arising from . (A.35) follows from Chebyshev's inequality.
Corollary A.17: In a random LDPC code with , almost surely as , the following property holds: if has weight , then given a codeword chosen uniformly at random,
Proof. Corollary A.14 shows that almost surely, the only parity-check with support in is the check itself (anything else would have weight smaller than ). Let denote the projection onto the bits in check . Notice that must be a vector space, since is a linear map. The dimension of this space must be exactly since we have exactly one unique check in this regime. Again by linearity, the distribution over random codewords must be uniform: if
then since, for every , codeword and are equally likely. The uniform distribution over all vectors with an even overlap with the check is given in (A.38).
B Learning random codes
In this section, we will show that the TDenseAM architecture above learns the codewords of classical low-density parity-check (LDPC) codes efficiently.
B.1 How many training examples are needed?
We now describe how the TDenseAM trains on random codewords of a high rate LDPC code with .
The first key observation is that the TDenseAMs do correctly learn the underlying code. In other words, the ground states of – after training on a large enough number of patterns – precisely match the codewords of the input code. Most excitingly, for any threshold – including – we do not need to see every random codeword in order to recover all of them as local minima of . Bounds on a sufficient number of codewords to learn the LDPC code are provided in the following proposition:
Proposition B.1: Suppose that we train the p-local TDenseAM architecture with threshold on P uniformly random codewords, from an LDPC code with -body weights and distance . Then if
for , we find a bijection between ground states of and codewords in V, with probability at least .
If we consider the usual dense associative memory , then the lowest energy states of are the codewords so long as
Note that the scaling in this equation is suboptimal, if our goal is to learn an accurate representation of the overall energy landscape. We return to that issue in Theorem B.12.
Proof. We first consider the case . is determined by the random variables
The distribution of these random variables is straightforward to see: each is 1 with probability 1 if represents a valid parity-check (here we have a slight abuse of notation), while it is a binomial random variable (an unbiased random walk with steps, normalized by ) otherwise. This distribution follows directly from the proof of Proposition A.3. By the assumption that was generated by at most -body checks, the TDenseAM will detect every parity-check in , so the remaining question is how large must be before there is a high probability that for each . We can easily address this question using Hoeffding's inequality (3.10). By the union bound, the probability that we fail and find is bounded by (using )
In the last step, we used (B.1) to give a bound on P.
The case of is similar, except that we can never truly threshold away every coupling. We can still obtain a very conservative bound as follows: there are fewer than possible parity-checks of weight . If for each , we find
The exponent of the polynomial scaling here is not expected to be optimal, and may depend on the energy landscape of the code itself. The key thing is that we do not expect that can ever be achieved when a = 0.
then we are guaranteed that only codewords are ground states of . The reason is as follows: as before, if , and since each bit will be contained in at least one parity-check (as the distance is larger than 1), the energy cost of an error will be positive: there will be at least one violated check, so the energy cost of any state with a violated parity-check, relative to any codeword, will be
using (B.5). So we should use Hoeffding's inequality (3.10) and ask that each , which occurs when (B.2) holds.
The above proposition guarantees that after seeing enough patterns, the TDenseAM learns the underlying code. Crucially, either (B.1) or even (B.2) are far smaller than the codewords of a random LDPC code. Therefore, the associative memory is not simply memorizing the training data, it is learning the underlying rules that generated the data set; namely, performing Hamiltonian learning. Amazingly, in the case , we do not even need to show the TDenseAM every linearly independent vector in V before it learns the entire vector space. The TDenseAM therefore truly learns to generalize on this problem, even going beyond interpolation and learning pattern after seeing and individually.
B.2 Dynamics of learning:
We will first discuss how the TDenseAM learns – in particular, the nature of the learned energy landscape as a function of – in the limit . In this regime, the TDenseAM becomes identical to the SAT learning algorithm of Valiant [15] applied to the XORSAT (LDPC) problem: we reject a constraint if we ever see it violated a single time. Namely, if and only if for every pair of training patterns .
In our discussion of the learning algorithm, it will be useful to separate out
where E is a true code Hamiltonian that we will learn, while is the spurious Hamiltonian that is sensitive to the specific training data we have seen. Proposition B.1 gives us a loose bound on how fast it takes for to become negligibly small or even zero. However, we would like to say more about what happens to as a function of P.
There are two useful ways to think about how the TDenseAM learns. Firstly, we can keep track of
J stands for the number of junk couplings that we have not unlearned, and is a proxy for how corrupted is by . For later use, we have also defined the indicator variables
The second thing we can keep track of is the rank of the learned codespace .
We will show that the way TDenseAM learns in the limit is rather different at early times depending on whether or , and so we will have to tackle those problems separately. The late time learning is very similar in both cases, so when we talk about late time behavior we will discuss both together.
Proposition B.2: Consider the task of learning a random LDPC code with using the TDenseAM. Then almost surely as , if for any , the learned rank of codewords is
Proof. When , the only allowed codes that TDenseAM can learn are disjoint repetition codes: indeed if and are constraints on the codespace, by transitivity , the allowed codewords correspond to independent subsets of which must all agree with each other. The rank of the code is the number of non-empty sets
For convenience, it is useful to “gauge fix” the first . If each is non-empty, then the rank of the learned code must be .
The most general code with corresponds to a set of repetition codes, wherein the first bits are arbitrary and the remaining bits are fixed. The probability that a given ends up in each bucket is , and each of these are independent events. The probability that a bucket has zero elements is
This event happens with probability so long as
In the limit of large k, this inequality is false for any , for any .
Proposition B.3: Let and . In the regime
(B.14) almost surely as , the rank of learned codewords is
Proof. We begin with a useful lemma:
Lemma B.4: Let denote a collection of the possible learned couplings. Then, in the limit , after training on random codewords,
where
Proof. When , (B.16) immediately follows from the training rule and Proposition A.3. Firstly, if the sole is a valid check, then every codeword satisfies it, so and the probability in (B.16) is 1. Secondly, if , the probability that patterns with match (which itself was with equal probability) is independently for each pattern, establishing (B.16) as well.
Next, suppose that , but and each check in is linearly independent. In this regime, we may apply Proposition A.4: the probability that all survive training on each pattern is : we must lie in an orbit that does not contain any .
An analogous argument applies in the case where but is not full-rank. The values of the are completely determined by knowledge of their values on a linearly independent subset, where we can apply the argument of the previous paragraph.
Lastly, suppose that . In this case, we know that every element of in the span of is never violated, so we must subtract these contributions from the count above. If we study the reduced set , a vector space of rank as given in (B.17), then it satisfies the previous case.
Observe that
The second equality follows from Lemma B.4: any two inequivalent I are linearly independent. Therefore, so long as the LDPC code has a subextensive fraction of all possible checks (the vast majority of possible checks are “junk” checks),
Chebyshev's inequality thus shows that
This shows that we see checks, almost surely as .
With high probability each bit is included in at most one surviving fake check. This is because for any , , again by the linear independence criterion in Proposition A.4 and Lemma B.4. Therefore, supposing that bit and , the probability that any other surviving check contains bit 1 is
(B.21)
This shows that almost every check is linearly independent as , and establishes (B.15). ☐
Theorem B.5: Consider the task of learning a random LDPC code with and , using the TDenseAM. Fix any , and suppose that
Then as , almost surely the learned rank of codewords is
Proof. The core strategy of this proof is to argue that when (B.22) is obeyed, each new observed codeword increases the rank only by 1. If we can establish this fact, (B.23) follows immediately from the fact that after being shown the first pattern , this is the unique ground state of if is odd, while if is even, and are both ground states.
To do this, we proceed as follows. Define
Lemma B.4 shows that the probability that any spurious check has survived is given by
which is quite small. At the same time, there are a huge number of spurious checks: , which naively already wins. However, we need to be careful: the spurious checks can themselves be highly redundant.
supp( )
supp( )

Figure 5: Illustration of in the case m = 5.
We will therefore establish (B.23) as follows. First, define to be the set of learned checks (modulo gauging by the first seen pattern) after patterns:
Without loss of generality for what follows, we set to simplify notation. We will show that for suitably small , with high probability. We do this by showing that for any two acting on disjoint bits, (w.h.p.) because it can be represented as a sum over exactly 2m checks that remain in . This latter fact will come from establishing the existence of a nice matching, which we define as follows:
Definition B.6 (Nice matching): Define the graph to be the connected subgraph of the bipartite complete graph minus a perfect matching: see Figure 5. A nice matching on is a collection of bits: such that there exists a sequential assignment of to the 2m vertices of , and to the edges of such that , , and contains every candidate check made out of a vertex along with its incident edges:
We also write
We will restrict our study to candidate matchings where , where is any subset of vertices chosen to ensure the following property:
Lemma B.7: Suppose that for some constant , and is sufficiently large. For any with , and constant , there exists a set with , such that the following holds. Let ; here denote the unit vectors in . For every coset , we have that are all linearly independent vectors. Therefore, when sampling random codewords , the random variables are i.i.d. Bernoulli random variables with .
Proof. Because we have , we know that , so any would suffice, for large enough Since the cosets span the entire space, there must be of them which are linearly independent. By Proposition A.4, the probability for each if . Moreover, even conditioned on arbitrary values of for , must be independent for all subsets of ; if this was not true, then there would be a linear combination of which violates Proposition A.4 by always taking the same value (0). Note that the TDenseAM does not need to learn – it’s role is constructive for the proof of Theorem B.5.
In what follows, we will condition on for and . Lemma B.7 shows us that all are independent variables. The strategy is now to show that there are typically many nice matchings in involving the two checks , which would immediately imply that . To do this, we introduce the random variable
We further introduce independent Bernoulli random variables , with (we will choose the value of later). It would suffice to argue that the following random variable is non-zero with high probability:
We do this by invoking the following improvement over Hoeffding's inequality, discussed in [32, 33]:
Lemma B.8: Let be Bernoulli random variables: . Define a graph on the , with connected to by an edge as infrequently as possible, while maintaining the following property: if disjoint index sets and share no edges in common, then and are independent random variables. Then
where
The idea is to apply this lemma to bound . Clearly if , there exists a nice matching of checks in , verifying that . We need to choose an incidence relation compatible with the requirements of Lemma B.8. A useful way to do this is to say that if and only if and and share at least one edge in common.
First, we evaluate
where the first combinatorial factor represents the number of candidate nice matchings: note that the order in which we assign the coordinates does matter, which is why there is not an additional . Lemma B.7 implies that in the coset space , the rank of the checks in the nice matching is – the only dependent combination is the sum of all checks (which equals ). Using Lemma B.4, we then have
Therefore, using (B.24),
On average, there are many candidate perfect matchings.
We now need to evaluate and to show that these perfect matchings are largely independent, so the probability of finding one is extremely high. The key observation is as follows:
Lemma B.9: Let and be two nice matchings ( ). If , then
In other words, any two matchings with many common checks must also share a large number of bits in common. As a consequence,
Proof. Recall that a common vector between and is shared only between the coordinates in . Delete the edges in from the graphs (isomorphic to ). The common vector must necessarily have disconnected both graphs into connected components: the only way to find a trivial relation involving an unremoved edge is to sum over both checks at its endpoints: all checks on a connected component must be included with
Recall the definition for at the end of Definition B.6.

Figure 6: An illustration of a connected component ; the subset A is highlighted in turquoise, and this example has along with . The red edges are the deleted edges which must have been removed in (B.38).
equal weight, and the sum over all checks is already a trivial constraint by construction. We deduce that
Now suppose that we choose a connected component of that contains left vertices and right vertices, as shown in Figure 6. Without loss of generality we may take . The number of edges that must have been removed is at least
The last inequality can be checked by brute force since .
Since if , we apply this cut bound to each component of post-deletion and find
where the second inequality uses that . This implies (B.35). (B.36) follows the fact that the rank of checks in and is and from Lemma B.4 and (B.33).
Let us then count the number of neighboring pairs in the adjacency graph on matchings. Clearly, for s > 0,
where the first factor counts the number of candidate identifications of two edges in the matching with the same bit, while the second factor bounds the number of independent bits to choose between the matchings.
Now we can bound as follows. Fix (all matchings are the same on average), and sum over all potentially correlated :
This sum can be broken up by rank as follows: using (B.40) for the case , and using Lemma B.9 for the case , we have
(B.42)
for sufficiently small , large n, and a suitable constant C whose exact value is unimportant. The dominant potential contribution comes from the r = 1 term with the smallest value of s.
Similarly it is easy to bound : a fixed matching has at most neighbors, so
Now let us put everything together. We want to ensure that and, additionally, , or more simply, . This happens so long as
From (B.34), we see that (B.44) is satisfied for large enough n if we take
Lemma B.8 then shows that almost surely as , any two spurious and non-overlapping checks obey . Indeed, the probability of a fixed pair falls as a stretched exponential in , so the probability of this event happening for any pair still vanishes at the same rate. By the union bound, the probability we have ever failed this test at any point is bounded by
for sufficiently large n. Since we have seen that almost surely as we never remove more than 1 check at a time at this small number of patterns, we establish (B.23).
B.3 Dynamics of learning: a = 0
Next, we consider the opposite limit of . In this limit, we may expect that following [10], generically serves as a simple memory at small – even though the dense associative memory is trained on random codewords, it will not uncover the rules that generated the data for some time. This is made precise in the following discussions.
The first result is to establish an absence of stability of typical unseen perturbations until is sufficiently large. More concretely:
Theorem B.10: Consider training the dense associative memory on a random LDPC code with weights . Consider comparing the learned energy at a true codeword to the learned energy at , where . If
then almost surely as ,
if , for -independent function , with .
Proof. Without loss of generality, we may consider the stability of the codeword (call it when converting to spin language), after training on random codewords , since the training ensemble is translation invariant on . It is most useful to express the dense associative memory energy function as
when a = 0. We will analyze larger spin flips biased towards a single observed pattern and show that typical such choices lower the energy of c = 0.
Towards this end, let us consider the following setup. Let
denote the sites where the first (randomly drawn) codeword differs from . Almost surely as , Corollary A.16 shows that
Let and define
We then consider the random variable
The goal will be to show that for large enough , almost surely when is sufficiently small. In order to show that fact, it is useful to define
since
It will also be useful to define
Let us first consider the case . (B.51) implies that
deterministically. Assume that is a fixed constant as . Using (B.51), we see that
In contrast, for , is a random variable. Some useful moments of this random variable are captured by the following lemma:
Lemma B.11: Letting E denote the code energy as in (B.7), for any :
Proof. Here it is useful to expand out
Using Proposition A.3, we see that when averaging over codewords , the only terms that survive are those where the product of form a valid parity-check. From Corollary A.14, we know that every valid parity-check will involve distinct bits. Using the definition of in (B.54) then establishes (B.59a).
Now we turn to the second moment. It is useful to write it as follows. Let denote ordered m-element lists. First average over random patterns :
Firstly, we can again use Proposition A.3 to conclude
Notice the following simple bound: since
is either 0 or -2, we have
By Corollary A.15, this sum is dominated by terms where and contain every bit an even number of times: if they contain some collection of bits , we see that is required for the average to be non-vanishing by Proposition A.3; the contribution over all such terms is bounded by if . In contrast the number of ordered lists and that together share an even number of each element is bounded by - the first combinatorial factor counts all the ways that indices can be paired up; is the number of bits that each pair can jointly be assigned. Notice that in this case, we also have
Therefore using that this contribution dominates , we find (B.59b).
The crucial thing we learn from Lemma B.11 is that are not heavy-tailed random variables; we can apply the central limit theorem to . We conclude that as with held fixed, is well approximated by a Gaussian random variable with mean and variance
Since is also random and has half almost surely, and by Corollary A.17 the sampled logical
is equally likely to have all allowed overlaps with a given check, we have:
(B.67)
The overall factor of counts the number of checks – each of which itself is included times because all possible orderings of the bits are allowed in .
Let us now combine everything together: we find that with high probability a real codeword is higher energy than our random perturbation towards a seen codeword ( ) if, using (A.32),
Indeed, the variance of scales as when , while , so it suffices to check that as , which is what (B.68) guarantees.
Theorem B.12: In the same setting as Theorem B.10, if , for any below the confinement scale of the code,
Therefore, for sufficiently large A, there must be a local minimum of closer to the true codeword than to any other.
Proof. This proof begins identically to that of Theorem B.10, but we will need to find more sophisticated bounds on the distribution of . Towards this end, for any , define
Notice that
Using elementary inequalities we find
Now let us consider the norms on the uniform distribution on : (slightly abusing notation between vs. )
Hölder's inequality then gives
Lemma B.13: The following inequality holds for any and some -independent :
Proof. This is a useful generalization of Corollary A.16 (which immediately follows from this result by taking ). To prove this more general result, we notice the following useful identity, similar to those used in establishing Kramers-Wannier duality [34]:
(B.76)
with at sufficiently small (because ). In the third line we used the combinatorial fact that there are at most connected (on the bit adjacency graph) clusters in an LDPC code [34], with , along with the fact that the smallest such cluster is (Corollary A.14) and check soundness (Theorem A.13). We see that
Markov's inequality gives
(B.75) follows from Gaussian-like scaling. More concretely,
(B.79)
for an O(1) constant . Since as becomes large, there exists a constant for which (B.75) holds.
Now the idea is to use Lemma B.13 to bound the tails of the probability distribution of . A second instrumental ingredient in this bound is the following “sub-Weibull” tail bound from [35] (we are deliberately simplifying/weakening their results, while maintaining sufficiency for our needs):
Theorem B.14: Let denote independent and identically distributed random variables with whose probability distribution is “sub-Weibull”: namely obeys, for some ,
Then there exists a function which is positive and finite for such that, for any ,
The strategy is to apply Theorem B.14 as follows: write
where was defined in (B.67). Then (averaged over codewords), so we can apply Theorem B.14. From the triangle inequality,
Next, combining Lemma B.13 with (B.74) and the fact that , we find
Then we have the following useful lemma [36]:
Lemma B.15: If for all , then (B.80) holds with
We now combine Lemma B.15 with (B.81) and (B.84) to find, as and with , must be sub-Weibull with . More precisely,
with
So the tail bound (B.86) is strong when we set (for constant to be determined). Recall that the regime of interest has , and we need the fluctuations in (B.86) to be sufficiently suppressed so that a union bound over all possible subsets does not find a single favorable spin flip. In other words, we need
or, recalling the binary entropy function h defined in (A.17),
Note that since as , we can only hope to do find such a for a fixed positive , which is what the theorem asks for.
In any event, let us finalize things. For obeying (B.89) we need
which would ensure that the cutoff in (B.86), along with the positive energy gain from given in (B.58), are not enough to push due to the cost of violating many of the (approximately) learned checks having arose from the contributions to . From Corollary A.9,
for any and for which Theorem A.11 ensures we have a expander code. Almost surely as ,
Solve this quadratic inequality for and call the solutions ; this establishes (B.69).
Theorem B.10 and Theorem B.12 together imply a clear crossover when where the denseAM establishes basins of stability around each codeword, as claimed in the main text. Let us now confirm that, as claimed in the main text, codewords are lower energy than random configurations once , which we formalize in the proposition below:
Proposition B.16: Starting at any codeword and flipping a random set of bits towards an unseen codeword, we find (using the notation of Theorem B.10) that with high probability as if for any .
Proof. We follow the proof of Theorem B.10, but if the bits we flip point us towards an unseen codeword, we simply lose the deterministic contribution from (B.66a). Then we see that
Since has approximately Gaussian fluctuations, almost surely as .
Before , we are relatively likely to see a true codeword higher energy than a random state, so it is hardly fair to say that we have “learned” the code at this point!
It would be very interesting to study the “mixed memories”, which have been studied in dense associative memories trained on random codewords [28], to the architecture trained on XORSAT codewords. We leave this to future work.
C Learning latent variables
With a sensible modification, the same TDenseAM architecture described above can (asymptotically) optimally recover latent variables – namely, degrees of freedom which are not shown to the model, but which sparsify the energy . This is not achievable for arbitrary problems [37]. However, random LDPC codes are a setting where latent variables are often easy to learn, and we will indeed provide some provable guarantees on their learnability in what follows.
Let us first set up the discussion at a high level. Divide up the bits of an LDPC code into observed variables which will be given to TDenseAM as training data, and latent variables which are not shown. Notice that denotes the number of latent bits. The energy function, as before, is a sum over parity-checks. We aim to generalize TDenseAM so that it can (1) identify latent variables and (2) learn a correct energy function .
As the LDPC problem is perfectly suited to TDenseAM, as discussed above, this will indeed be possible in many circumstances. The strategy that we will explore is to identify latent variables by their observable shadows, which are defined as follows:
Definition C.1 (Observable m-shadow): A latent variable in an LDPC code with maximal check weight has an observable -shadow if there exist subsets, any two of which obey and for which .
Before continuing, let us make a few caveats. (1) is not necessarily unique – indeed, we’ll comment more on this shortly! (2) We do not rule out vastly more effective ways to discover latent variables than observable shadows. Instead, we show that the observable shadow condition allows for a beautifully simple learning algorithm to discover them, and that many random codes guarantee observable shadows for latent bits, even when .
Returning to Definition C.1, the key observation is that is a parity-check involving at most 2m - 2 bits. Therefore, we propose the following “algorithm” which generalizes TDenseAM to the latent setting. We should emphasize that exactly as described, this algorithm is tailor-made for XORSAT/LDPC problems (as was TDenseAM); however, there is a natural extension of the philosophy to more generic problems.
Algorithm C.2 (p-latent TDenseAM for XORSAT): The p-latent TDenseAM architecture is a deterministic latent variable learner for XORSAT which iteratively proceeds as follows. Let denote the initial set of observed variables. Given patterns, use TDenseAM to learn all parity-checks of weight - collect them into a parity-check matrix . Now iterate the following algorithm, beginning at :
- Run TDenseAM to learn all parity-checks of weight ; collect them into parity-check matrix . Let
denote genuinely new higher-order constraints discovered.
- Suppose there exist cosets such that every has a representative of Hamming weight , and for every pair, . Then introduce a latent bit such that the following parity-checks are obeyed:
In other words, h has an observable p-shadow (Definition C.1).
- If no is found, terminate the process. Else, append to the observed variables: . Append learned parity-checks (C.2) to to make . Then send and repeat.
The 2-latent TDenseAM is an aggressive learner, but will necessarily introduce many redundant latent variables. As a simple example, if m = 3 and we observe , the 2-latent learner does not know whether to introduce vs. . In contrast, the 3-latent TDenseAM is more cautious; as such one may expect for it to have a better performance guarantee. Indeed, the 3-latent learning rule is analogous to those which have been used in previous studies of latent sparse learning [25, 26]. In the context of the
XORSAT problem, we can prove that the 3-latent TDenseAM is capable of learning an extensive number of latent variables, with high probability, on a random realization of the problem.
Theorem C.3: Consider a random LDPC code with , and if . Decompose the bit set into observed and latent bits. There exists constant such that, for sufficiently large , if , the 3-latent TDenseAM architecture will learn every latent bit correctly (and no spurious latent bits) almost surely as , after seeing at most
random codewords as training examples, for any .
Proof. Theorem A.11 shows that a random LDPC code is a expander with some , and any , almost surely as . The strategy of the proof will be to assume -expansion with suitable and (which holds with high probability), and then demonstrate that conditioned on this likely event, the strict latent TDenseAM learns a latent variable if and only if it is in . The key idea is that a certain kind of observable 3-shadow guarantees (certifies) the existence of a latent bit:
Lemma C.4: Define a clean 3-shadow as a triple of observed parity-checks of size :
with sets , all three sets disjoint, and none of the parity-checks explainable as the union of two smaller observed checks. Then, given the code is a -expander with
a clean 3-shadow certifies the existence of a unique (latent) bit such that the code had parity-checks
Proof. From Theorem A.13, we see that if then we may take with high probability as . This puts us in the regime where Definition A.7 applies: for any , the maximal number of parity-checks that can add together to make a parity-check of size obeys:
Clearly we must have , and the inequality is violated at if (C.5) is obeyed. Hence
(C.5) ensures that every parity-check of size can be written as the sum of exactly two parity-checks.
Now, suppose that we see the pattern (C.4). There are exactly two ways this can happen. The first is that we see the pattern (C.6), where may or may not be latent – if it is not, we clearly should not introduce a new latent variable! The other possibility is that
Because by assumption we have seen observed variables between the observed checks (C.4), the pattern (C.8) can only be observed if all bits are already observed – therefore there will be no latent variables. Therefore, there is a latent variable if and only if the constraints (C.4) cannot be deduced from any of the observed lower-order constraints.
It is clear that seeing a clean 3-shadow of a latent variable is a guarantee (with high probability) that we will correctly infer the intended latent variable. Now we prove that:
Lemma C.5: If , then almost surely as , there exists a latent variable with a clean 3-shadow.
Note that we will apply this lemma at each iteration of Algorithm C.2, so is shrinking as we add more latent variables to the observed set.
Proof. If the latent subgraph of the LDPC code was a tree, this property would follow immediately, because . To prove this fact, we will need to show that the latent subgraph is “close enough” to a tree to ensure the existence of a clean 3-shadow.
Let denote the set of bits which have the following property:
We observe that if and only if is contained in a subgraph of the Tanner graph isomorphic to a 4-cycle. Furthermore, Proposition A.12 shows us that almost surely, is a collection of disconnected 4-cycles in the Tanner graph. Indeed, suppose that there was a set of 3 latent bits, all of which were in and connected to each other. This would require a finite subgraph of the Tanner graph with 2 loops, which happens with probability and can be neglected. An analogous argument further shows that for any fixed distance , cannot contain two pairs of bits within a fixed distance of each other.
With this in mind, we now provide a proof by contradiction for the lemma. Suppose that the latent set had no clean 3-shadows. Without loss of generality, we may assume that is connected: disconnected components cannot hinder learning any other component. Because has no clean 3-shadows, every bit in must have at most 2 unique-neighbor checks, while every bit in
has at most 3 unique-neighbor checks. Comparing with the definition of expansion, we have that
(C.10)
Notice that as long as we enforce (C.5) and and ,
Therefore, (C.10) can only hold if
Let us analyze (C.12) on each connected component of . Clearly a single isolated point in is not possible, and such an isolated latent bit has a clean- -shadow. So now consider the case where is not empty. If there is a single pair of bits in , then (C.12) implies that . So the entire connected latent component is of shared bits, which is a contradiction: each such bit still has a clean -shadow. If there are multiple disconnected components of in the same connected component of , then we know there is a path of length separating them for any . Using this result, we deduce that the largest possible density
arises when is a tree-like subgraph with pairs separated by . Take : if , we find that (C.13) contradicts (C.12). Therefore, in all possible cases, we have found a contradiction, completing the proof.
It is now clear that the strict latent TDenseAM will provably converge by learning, one at a time, the latent bits by detecting their clean 3-shadows. Lemma C.4 requires the condition (C.5) which enforces if , while otherwise placing no constraints if . The 3-latent TDenseAM architecture correctly learns every visible weight- constraint, by Proposition B.1, if we train on the number of patterns given in (C.3), almost surely as . Therefore the 3-latent TDenseAM succeeds.
References
[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).
[2] Andrey Gromov, “Grokking modular arithmetic,” (2023), arXiv:2301.02679 [cs.LG].
[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] 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).
[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] 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.
[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.
[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] 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] Dmitry Krotov and John J Hopfield, “Dense associative memory for pattern recognition,” Proc. NeurIPS 30, 1180 (2016).
[11] John J. Hopfield, “Neural networks and physical systems with emergent collective computational abilities,” Proc. Natl. Acad. Sci. 79, 2554–2558 (1982).
[12] Michael Sipser and Daniel A. Spielman, “Expander codes,” IEEE Transactions on Information Theory 42, 1710–1722 (1996).
[13] T. Richardson and R. Urbanke, Modern Coding Theory (Cambridge University Press, 2008).
[14] Dmitry Krotov and John Hopfield, “Dense associative memory is robust to adversarial inputs,” Neural computation 30, 3151–3167 (2018).
[15] L. G. Valiant, "A theory of the learnable," Communications of the ACM 27, 1134 (1984).
[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.
[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.
[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.
[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.
[20] Marc Mézard and Andrea Montanari, Information, Physics, and Computation (Oxford University Press, Oxford, 2009).
[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.
[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.
[23] M. Cluzeau and J-P. Tillich, “On the code reverse engineering problem,” in Proc. IEEE. Int. Symp. Inf. Th. 2008 (2008) p. 634.
[24] T. Kaufman and M. Sudan, “Sparse random linear codes are locally decodable and testable,” Proc. FOCS 48, 590 (2007).
[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.
[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].
[27] Dmitry Krotov, Benjamin Hoover, Parikshit Ram, and Bao Pham, “Modern methods in associative memory,” arXiv preprint arXiv:2507.06211 (2025).
[28] Véronique Gayrard, "Mixed memories in Hopfield networks," arXiv:2504.04879.
[29] A. Lucas, "Learning modular addition as a latent SAT problem," (unpublished).
[30] B. Bollobás, Random Graphs, 2nd ed. (Cambridge University Press, 2001).
[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] 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).
[33] S. Janson, "New versions of Suen's correlation inequality," Random Struct. Alg. 13, 467 (1998).
[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].
[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).
[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] M. Kearns and L. Valiant, “Cryptographic Limitations on Learning Boolean Formulae and Finite Automata,” J. ACM 41, 67 (1994).