Provably Optimal Memory Capacity for Modern Hopfield Models: Transformer-Compatible Dense Associative Memories as Spherical Codes

We study the optimal memorization capacity of modern Hopfield models and Kernelized Hopfield Models (KHMs), a transformer-compatible class of Dense Associative Memories. We present a tight analysis by establishing a connection between the memory configuration of KHMs and spherical codes from information theory. Specifically, we treat the stored memory set as a specialized spherical code. This enables us to cast the memorization problem in KHMs into a point arrangement problem on a hypersphere. We show that the optimal capacity of KHMs occurs when the feature space allows memories to form an optimal spherical code. This unique perspective leads to: (i) An analysis of how KHMs achieve optimal memory capacity, and identify corresponding necessary conditions. Importantly, we establish an upper capacity bound that matches the well-known exponential lower bound in the literature. This provides the first tight and optimal asymptotic memory capacity for modern Hopfield models. (ii) A sub-linear time algorithm $\mathtt{U}\text{-}\mathtt{Hop}$+ to reach KHMs' optimal capacity. (iii) An analysis of the scaling behavior of the required feature dimension relative to the number of stored memories. These efforts improve both the retrieval capability of KHMs and the representation learning of corresponding transformers. Experimentally, we provide thorough numerical results to back up theoretical findings.

Paper

Similar papers

Peer review

Reviewer vthX6/10 · confidence 4/52024-07-11

Summary

Suggest a method to optimize kernel versions of Modern Hopfield Models by mapping memories onto well-separated values on a sphere in feature space. Shows that the spherical arrangement of memories is optimal for retrieval (e.g., maximize capacity) and thus can improve upon the linear kernel [Wu et al. 2024a], which optimises memory separation.

Strengths

* Originality: the idea presented is quite simple and intuitive, but the perfected procedure is non-trivial and can potentially improve memory performance across a large family of relevant MNM-s. * Clarity: the submission is clearly written and well organized.

Weaknesses

* Quality: the algorithm's main justification is a lower bound that is not shown to be tight, so optimizing the minimal overlap between memories is not well supported (here). * Quality: if the main claim of the paper is improving the capacity to store memories, I would expect a numerical validation that the algorithm improves the number of memories that may be stored or increases the amount of noise that may be tolerated. The included results (sections 3.1 and 3.2) are only qualitative and are achieved on toy problems. Such a comparison can be done relative to plain-vanilla dense MHM or to [Wu et al. 2024a]. * Significance: the results are mostly of practical importance for practitioners who wish to implement MHM with an optimal kernel. For that crowd, it is not that important if the algorithm is based on a novel lower bound but that the algorithm works, which needs to be better established.

Questions

1. How does the lower bound on memory capacity (lemma 2.1) contribute to the derived algorithm? It’s dependance on R and D of the embedding, but those are not optimized for in the algorithm. Furthermore, it doesn’t depend on the minimal memory separation. 2. What is Lambda in Definition 2.8, Theorem 2.1? 3. Is the lower bound from definition 2.7 tight? Can you establish it is not vacuous?

Rating

6

Confidence

4

Soundness

3

Presentation

3

Contribution

2

Limitations

The authors have presented a theoretical approach based on a lower bound for capacity, which may not directly translate to improvement in task performance and has not shown such improvements through experiments.

Reviewer LSVx7/10 · confidence 3/52024-07-12

Summary

This work provides a theoretical analysis of the optimal capacity on both Modern Hopfield Networks (MHNs) and Kernelized Hopfield Networks (KHNs). Specifically, it seeks to answer four fundamental problems: 1. How does memory capacity affect the gap between memories? 2. Given a fixed feature dimensionality, how to select an optimal separation function? 3. Is there a simpler and more efficient algorithm which optimize the kernel? 4. How to connect the gap between memories and the optimal capacity of KHNs theoretically? Through the viewing of the memory set as a spherical code, the work establishes the problem of storing memories as a hard-max problem of maximizing the number of patterns stored, while ensuring that the angle between them is at least a certain constant (which the work does show). Consequently, this portrayal of the problem enables a simpler algorithm to optimize the kernel in contrast to the previous work UHop. Furthermore, the work illustrates that the optimal memory capacity is strongly dependent on the projection function $\phi$, such that its optimality maximizes the gap (or angle) between each pair of memories.

Strengths

The formulation of the problem presented in the work is great while the proofs are easy to follow. Moreover, the work achieves its goals in answering its four fundamental questions while providing a nice associative memory framework, which could possibly also be applied to other MHNs.

Weaknesses

There is a lack of experimentation in this work. It would be great for the work to have comparisons, similar to those detailed in [Uhop](https://arxiv.org/pdf/2404.03827).

Questions

For figure 4, what is the gray dot in the center of the circle? Is it an image (of a class) in CIFAR or just a point indicating the center? For the derivative of the RHS of the bound, $\nabla^\phi_\text{min} + \frac{1}{2\beta} \ln (\frac{1}{2} \nabla^\phi_\text{min}) \geq \frac{1}{\beta} \ln (2 (M - 1))$, is it not $\frac{1}{\beta (M - 1)}$ instead of $\frac{1}{2\beta M}$? Is it possible to see the loss curve for MNIST when optimizing $\mathbf{W}$? It would be great to see the stability of the new $\mathcal{L}$ just to get a sense of $O(\frac{1}{-4tR^2 - \mathcal{L}^*_\phi(\Theta)})$.

Rating

7

Confidence

3

Soundness

4

Presentation

4

Contribution

4

Limitations

There is a significant lack of experimentation (or comparisons) in this work. Other types of MHN might require modifications or a different framework to analyze their optimal capacity and compatibility with KHNs. The feature map is rather simple --- it is a linear affine function. Lastly, the spherical code framework only considers normalized points on the hypersphere.

Reviewer U6Ut5/10 · confidence 5/52024-07-12

Summary

The paper is a theoretical analysis of the memory capacity of MHMs and KHMs. It establishes a connection between memory capacity and spherical codes. A method for approximating optimal memory capacity is introduced. Experiments are conducted to validate the theoretical findings.

Strengths

The paper is well written and easy to follow. The memory capacity is an important problem that can have a significant impact on SOTA architectures like Transformers. The paper is an interesting theoretical discussion and shows a connection between memory and spherical codes in an original manner. The theoretical framework and parts of the proofs are based on [Ramsauer et al., 2020] with adaptions to KHMs. These previous concepts are extended to get results for optimal memory capacity and to introduce an objective for optimal memory capacity. This objective is relaxed by an "average separation loss" introduced in [Wu et al, 2024a].

Weaknesses

The optimization procedure of U-Hop is similar U-Hop+ i.e., Gradient Descent is replaced by PGD. Due to this similarity U-Hop should have been added as baseline. Since in the standard case MHMs use learnable weight matrices (as can be seen in Eq. 10 of [Ramsauer et al., 2020] and other publications using MHMs) there should have been a comparison to these MHMs using gradient descent based on the average separation loss. While memory capacity is an important property it is not immediately clear how much it helps for learning tasks. Therefore, experiments in similar vein to [Wu et al, 2024a] should have been conducted on these tasks.

Questions

How do you make sure that in Algorithm 1 the weight matrix W keeps the full column rank property from Definition 2.7?

Rating

5

Confidence

5

Soundness

3

Presentation

3

Contribution

3

Limitations

Yes.

Reviewer UbwM5/10 · confidence 5/52024-07-18

Summary

Modern Hopfield Networks (MHNs) are limited because they require sufficient minimal separation $\Delta_{\min}$ for theoretical guarantee. Kernelized Hopfield Models (KHNs) mitigate this limitation by storing the memories in the feature space. In particular, theoretical analysis in [Wu et al., 2024a] uses a linear kernel. The current paper proposes an algorithm to find the "optimal" feature map using spherical coding. By solving a surrogate optimization problem whose solution converges to the HardMax problem asymptotically with vanishing temperature, the algorithm improves the memory capacity.

Strengths

MHNs emerge as a powerful tool for theoretical understanding of neural networks such as Transformers. The current paper builds upon KHNs and gives analysis of necessary conditions for KHNs to achieve optimal memory capacity. Further, a sub-linear time algorithm is proposed to optimize the feature map.

Weaknesses

Prior work on KHNs already has analysis using linear kernel. It would be helpful to showcase the improvement brought by the current algorithm to improve clarity and contextualization relative to prior work. Moreover, the experiments only demonstrate the convergence property of the iterations. It would be nice to have more practical experiments on tasks such as multiple instance learning and retrieval. I could improve my evaluation if the authors would address the questions below.

Questions

1. Since MHN is a special case of KHN, how do the current results reduce to the MHN results in [Ramsauer et al., 2020]? Are there any improvements? 2. Definition 2.7 assumes that the patterns are normalized. This assumption is not explicitly stated elsewhere and are not well-justified. 3. Definition 2.8 is more like a statement rather than a definition. Why should the definition lead to the conclusion that "there is a feature map $\Phi$ such that $\Phi(V)$ is a memory code"? 4. Is the convergence in Theorem 2.2 pointwise convergence or uniform convergence? For a given $\tau>0,$ what's the error rate? 5. The proposed algorithm learns a linear map, what about non-linear maps? 6. In line 597, since you are referring to a known upper bound in a book, it would be better to provide more details for the reader to find the result. There are some typos: Line 48: does -> is Line 105: lower bounded by what? Definition 2.5: It seems that there should be an arg in front of minmax Definition 2.7: satisfies -> satisfy

Rating

5

Confidence

5

Soundness

3

Presentation

2

Contribution

3

Limitations

The paper is of theoretical nature. A paragraph on limitation is given in the main content.

Authorsrebuttal2024-08-12

Thank you very much for the response. > **Q1:** In Fig. 3 of the attached... **Response:** It is almost overlapped with the Generalized Sparse Hopfield + U-hop+ line. > **Q2:** Could you elaborate on how it is derived from Definitions 2.2 and 2.7? **Response:** We apologize for the confusion. The logic behind this is that Def 2.2 leads to Def 2.7, and then Def 2.7 leads to the maximal capacity as we refer to the solution of the $\max_{ \Phi(V) } | \Phi(V) |$, and $\tilde{\Phi}$ is the solution of $\argmax_{ \Phi } \max_{ \Phi(V) } | \Phi(V) |$. > **Q3:** I don't think my question Q4 is addressed. **Response:** With the same $\Xi$ and $\Phi$, $\mathcal{L}_0$ converges uniformly to the HardMax loss with same error rate of $\epsilon = O(\tau \log M)$. However, since Thm 2.2 considers two optimization problems, it is indeed $\Gamma$-convergence between these two minimization problems (convergence for functionals). With the property of $\Gamma$-convergence, the minimizers of one minimization problem will also converges to another. We will address that in the proof of our manuscript. ____ Thanks again for the response and your insightful review, we hope our responses address your concerns.

Reviewer UbwM2024-08-13

Thank you for the response. However, I think there are still some misunderstandings. Q1: Could you provide any intuition on why the Sparse Hopfield + U-hop+ line is almost overlapped with the Generalized Sparse Hopfield + U-hop+ line? Q2: In my previous question, I was wondering why Definition/Lemma 2.8 leads to the conclusion that "there is a feature map such that is a memory code". It seems to me that there are some important premises for Memory Code (Definition 2.7). One is the assumption that the patterns are normalized. Another is that the feature map $\Phi\in \mathcal{H}$ is linear.

Authorsrebuttal2024-08-13

Glady! > **Q1:** Could you provide any intuition on why the Sparse Hopfield + U-hop+ line is almost overlapped with the Generalized Sparse Hopfield + U-hop+ line? **Response:** Sparse Hopfield is a special case of Generalized Sparse Hopfield (GSH) with the sparsity parameter $\alpha=2$. Notably, $\alpha=2$ represents the most sparse GSH. Therefore, for datasets with high sparsity, the two may overlap. > **Q2:** In my previous question, I was wondering why Definition/Lemma 2.8 leads to the conclusion that "there is a feature map such that is a memory code". It seems to me that there are some important premises for Memory Code (Definition 2.7). One is the assumption that the patterns are normalized. Another is that the feature map is linear. **Response:** Thanks for pointing this out. We notice our expression causes confusion. We have changed the paragraph into the following: "From this definition, with a fixed $D_\Phi$, for some set of patterns $\mathcal{V}$ that has size $M^*$, there might exist a function $\tilde{\Phi} : \mathbb{R}^d \rightarrow \mathbb{R}^{D_\Phi}$, such that it pushes memories further from each other to the level where $\tilde{\Phi} ( \mathcal{V} )$ is a memory code. In other words, if one hopes to store all points in $\mathcal{V}$ with KHNs, the objective is to find an appropriate $\tilde{\Phi}$." **This paragraph is meant to be an intuitive explanation rather than a theoretical result. Thank you again for pointing this out, we have revised our manuscript accordingly.**

Authorsrebuttal2024-08-13

A Gentle Reminder

Dear Reviewer, As the discussion period coming to its end, we want to check if our latest response has addressed your concerns. We have responded to the reviewer’s followup questions and concerns. If resolved, we respectfully ask that you consider increasing your score to reflect your satisfaction. Please let us know if you have any further questions or need clarification. Thank you! Best regards, Authors

Reviewer UbwM2024-08-14

Thank you for your clarifications. It appears to me that the datasets you have selected for evaluations are those with high sparsity, which makes the two curves overlap. I'm not sure such comparisons are fair. However, I think the current work makes some solid theoretical contributions. Thus, I will keep my score.

Reviewer vthX2024-08-09

Response to rebuttal

I appreciate the author's improvements in the manuscript and believe my main concerns have been addressed. I'm especially impressed by the added experiments, which, to me, provide important empirical support to the mathematical justification. I will raise my score accordingly.

Reviewer LSVx2024-08-10

Thank you to the authors for their detailed response and hard work. Based on the provided the results, I am happy enough to raise my score to 7. Side comments: Yes, indeed the slight in error in RHS of the bound does not change the main statement. The error bars of each line in the plots provided in the response are based on standard error? If not, see if plotting the error bars as standard error could help aesthetically. Cheers.

Authorsrebuttal2024-08-11

Thank you again for your constructive comments. We truly appreciate your thorough review! We will take the aesthetic suggestion into consideration. Thank you!

Reviewer UbwM2024-08-12

Thank you for the detailed rebuttal. - In Fig. 3 of the attached pdf. It seems the results for "Sparse Hopfield + U-hop+" is missing. - > "We recognize this potential confusion and have changed the definition to a Lemma, as it is a derived result from Definitions 2.2 and 2.7." Could you elaborate on how it is derived from Definitions 2.2 and 2.7? - I don't think my question Q4 is addressed.

Reviewer U6Ut2024-08-12

Thanks to the authors for the clarifications. Thus, I will keep my score.

Program Chairsdecision2024-09-25

Decision

Accept (poster)

© 2026 NYSGPT2525 LLC