Uniform Memory Retrieval with Larger Capacity for Modern Hopfield Models
Dennis Wu, Jerry Yao-Chieh Hu, Teng-Yun Hsiao, Han Liu
Introduction
We address the memory confusion problem in the modern Hopfield models by proposing a two-stage optimization formulation, termed , for the memory retrieval dynamics of modern Hopfield models. We construct the similarity measure of modern Hopfield models with a learnable kernel. The feature map of the kernel is trained by maximizing the separation among the entire stored memory set (Figure 2). This allows Hopfield models under to distinguish different memory patterns with larger separation and hence achieve larger memory capacity.
For all , let be the finite radius of each sphere centered at memory pattern . We say is stored if all are generalized fixed points of , , and for . We say is -retrieved by with for an error , if .
Let be the separation between a memory pattern from all other memories in , and be the largest norm among memory patterns. Ramsauer et al. 2020 gives the retrieval error bound:
for any . This bound is crucial not only for characterizing retrieval quality but also, in capacity analysis, as a necessary condition for pattern to be stored in the model (Hu et al. 2023, Theorem 3.1). Yet, it depends on .
measures the distance from a given to the nearest memory pattern in . measures the minimal separation among all stored memories . Hence, they are both -dependent. This -dependence in (1.3) results in potential fuzzy retrievals, namely metastable states caused by multiple nearby local minima in the energy landscape, especially when is small. When this occurs, these fuzzy retrievals deviate the retrieval process from the ground truth, thereby hampering performance.
This fuzzy memory (memory confusion) issue is well-known in literature. The dense associative memory model (Krotov and Hopfield 2016) tries to solve this issue by using polynomial energy fucntion. The modern Hopfield models (Demircigil et al. 2017; Ramsauer et al. 2020; Hu et al. 2023; Wu et al. 2024; Hu et al. 2024b) try to solve this issue by using exponential energy functions. However, all these attempts still rely on the quality of . In this work, we rethink the use of inner-product similarity measure (i.e. in (1.2)), and consider it as primary source of the fuzzy memory problem. Specifically, due to its Euclidean nature, inner-product assigns equal importance to all dimensions of patterns and yields small if they ( and some ) share similar direction. This motivate us to replace the overlap (inner product) construction of the energy function with a similarity measure utilizing this -dependence.
We introduce a learnable feature map that maps energy to a kernel space with kernel . The resulting kernelized energy , and its corresponding retrieval dynamics satisfy the defining properties of modern Hopfield models: convergence between local minima of and fixed points of retrieval dynamics . This allows us to construct a separation loss that distinguishes the local minima of by separating stored memory patterns in kernel space.
Methodologically, we introduce Uniform Hopfield Memory Retrieval (). It is a two-stage optimization formulation. The first stage is separation loss minimization, distancing stored memory patterns in kernel space. The second stage performs energy minimization with the kernel-induced . The first stage enhanced , making it able to relocate its local minima to a more separated coordinate. As a result, modern Hopfield models under is able to obtain improved memory capacity.
Empirically, improves memory retrieval outcomes by a large margin comparing to other baselines. When applied to deep learning scenarios, significantly improves model’s memorization capacity, generalization and convergence speed. We show that improves memory retrieval tasks by an average 30% margin even under a single iteration of separation minimization, and learning tasks by an average 3% margin.
Section 2 presents . Section 3 connects to deep learning. Section 4 conducts extensive numerical experiments to support . Appendix includes proofs, experimental details, and additional experimental studies.
𝚄-𝙷𝚘𝚙\mathtt{U\text{-}Hop}: Retrieval as Two-Stage Optimization
In this section, Section 2.1 introduces a learnable feature map that maps patterns and the energy function into a kernel space, and demonstrate the fixed-point convergence property of kernelized modern Hopfield models. Section 2.2 presents (Algorithm 1), a two-stage algorithm for the kernel learning with optimal theoretical guarantees. It maximizes pattern separation by minimizing a novel Separation Loss.
In this section, we first parameterize the similarity measure(s) in modern Hopfield model(s) with a learnable kernel (via feature map (2.1)), and then show the induced models (with energy (2.2)) satisfying the defining properties of modern Hopfield models (Theorem 2.1, Lemma 2.1).
with . Section D.1 includes the definitions of and Sparsemax.
With 2.1, the energy function was monotonically decreased by the following retrieval dynamics:
where , and .
By 2.1 and the convexity of , there exists an inverse map that transforms the CCCP results in kernel space back to the state space, where and are located. We then complete the proof using the Concave-Convex Procedure (CCCP) and the convex conjugate construction following (Hu et al. 2023; Wu et al. 2024). See Section E.2 for a detailed proof. ∎
The introduction of releases similarity measure from Euclidean inner-product to a learnable form via the weight of the features map . Moreover, the new Hopfield model ((2.2) and (2.4)) includes all deep learning compatible existing modern Hopfield models (Hu et al. 2023; Wu et al. 2024; Ramsauer et al. 2020). If we replace the kernel with inner-product , then (2.2) reduces back to the general sparse model Hopfield model (Wu et al. 2024) Recall that the general sparse Hopfield model encompasses both dense (Ramsauer et al. 2020) and sparse (Hu et al. 2023) models as its special cases..
While Theorem 2.1 guarantees the monotonic minimization of energy using , the fixed point of might not be the local minima of according to Sriperumbudur and Lanckriet 2009. Therefore, we provide the next lemma to ensure their alignment, following (Hu et al. 2023; Wu et al. 2024; Ramsauer et al. 2020; Sriperumbudur and Lanckriet 2009).
Given the energy function Equation 2.2 and retrieval dynamics Equation 2.4, respectively. For any sequence generated by the iteration , all limit points of this sequence are stationary points of .
By the monotonic energy minimization property of (Theorem 2.1) along with (Hu et al. 2023, Lemma 2.2), we prove this through Zangwill’s global convergence theory (Zangwill 1969; Sriperumbudur and Lanckriet 2009). See Section E.1 for a detailed proof. ∎
In summary, with , the parameterized similarity measure introduces an additional degree of freedom for us to relocate the minima of energy landscape . We show that the Uniform Memory Hopfield Energy (2.2) and its induced retrieval dynamics (2.4) satisfies the defining properties of modern Hopfield models (Theorem 2.1 and Lemma 2.1). Importantly, Lemma 2.1 states that minimizing the energy with also leads to convergence to the fixed point of .
This is pivotal in motivating our next step: constructing a separation loss . This loss distinguishes the local minima of by separating stored memory patterns in the kernel space. With , we then formulate the memory retrieval dynamics of the modern Hopfield associative memory model as a two-stage optimization, termed . This includes an additional stage of separation maximization (by learning the kernel), significantly enhancing memory capacity.
For all , let be the finite radius of each (kernelized) sphere centered at (kernelized) memory pattern . We say is stored if there exists a generalized fixed point of , such that , to which all limit points converge to, and for . We say is -retrieved by with for an error .
2 Separation Loss and 𝚄-𝙷𝚘𝚙\mathtt{U\text{-}Hop}
In this section, we first introduce a separation loss (Definition 2.2) over the stored memory set . Minimizing results in the separation of stored patterns within any given . Consequently, we incorporate this separation-maximization step into the standard memory retrieval process ((2.4)), leading to a novel two-stage formulation/algorithm, , for memory retrieval (Algorithm 1).
indicates the logarithm of average Gaussian separation of vector pairs over . Naturally, minimization of leads to an on-average dissimilarity among kernelized memory patterns, i.e., . Notably, is convex by design and hence exists an optimizer the maximizes the average distance between all possible memory pattern pairs.
Now we introduce Algorithm 1, the Uniform Memory Retrieval , for learning a suitable kernel and then retrieving stored memory from the learned kernel space.
Algorithm 1 is a 2-stage optimization process. For the first stage, we run iterations of kernel learning to minimize the separation loss, thus resulting in larger for . Next, we rescale each row of the affine matrix to ensure the magnitude remains the same for memory patterns. For the second stage, we run update steps for the retrieval dynamics, thus resulting in Hopfield energy minimization. Note that the learned kernel results in a new energy landscape of , and is expected to encode memory patterns into local minima that separates from all other memory patterns.
3 Exact Memory Retrieval
Let be fixed points of . By Definition 2.1 and Hu et al. 2023, the retrieval error exhibits a naive bound
The term forbids the exact memory retrieval. Explicitly, exact memory retrieval requires the memory pattern to be the fixed point of , namely . With this observation, we deduce the condition of exact retrieval
where is the one-hot vector with the -th element as . By plugging into , we see it is a fixed point and retrieves the target memory only when (2.6) holds. In the standard modern Hopfield model (utilizing the Sep function), the inability of to satisfy (2.6) results in a lack of exact retrieval (Martins et al. 2023), thereby preventing the modern Hopfield network from converging to a single memory pattern.
To combat this, we show achieves exact memory retrieval when , based on the sparse extensions of modern Hopfield model (Wu et al. 2024; Hu et al. 2023; Martins et al. 2023). Specifically, we study the application of with -EntMax as separation when .
Let be from Theorem 2.1 with . Let a real-valued kernel with feature map . Let . Supposed the query , is the fixed point of if the following condition is satisfied:
From (2.7), minimizing the separation loss gives the benefit of having the memory pattern to be the fixed point of . As a result, Sparse and Generalized Sparse Hopfield models (Hu et al. 2023; Martins et al. 2023; Wu et al. 2024) under further improves the retrieval accuracy. The next corollary is an extension of the above theorem where we observe the condition with respect to the lipschitzness of .
Let be the Lipschitz constant of . Following Theorem 2.2, achieves exact memory retrieval if
See Section E.3 for a detailed proof. Note that with defined in (2.1), is always -Lipschitz. ∎
Connecting to Modern Deep Learning
To incorporate into deep learning, we first introduce a kernelized Hopfield layer. Here we propose a deep learning compatible layer based on as
Note that this is a kernelized version of (Ramsauer et al. 2020), (Hu et al. 2023) and (Wu et al. 2024) layers, which serve as an alternative to attention mechanism variants.
Next, we introduce the average separation loss for deep learning compatible .
Specifically, is the loss minimizer of .
The empirical validation is in Appendix G. This theorem shows that with a suitable kernel, the expressiveness of layers under reaches its full potential. The main difference between this new loss function and the separation loss is the square on . Note that this theorem requires for any given , , which implies it is only possible when . In the context of deep learning, the patch size must not be larger than the hidden dimension to realize this result. This theorem extends the representation theorem in (Bhojanapalli et al. 2020) to a practical setting, showing that overcomes the low-rank bottleneck of the attention mechanism and Hopfield layer as well.
The next algorithm is the realization of searching for under supervised learning schema. Consider a supervised learning problem with input data , label , model , where consists of one layer of “ + Hopfield layer”. The stage-I of is parameterized by , and is parameterized be .
Experimental Studies
To validate the efficacy of , we test it on both associative memory retrieval task and deep learning task (image classification) with multiple real world datasets.
The memory retrieval task involves retrieving a memory pattern from a stored memory set. In particular, this experiment aim to reconstruct memories based on a query. The query is generated by randomly masking 50% of pixels in the target image. We compare our method against several modern Hopfield models (Hu et al. 2023; Ramsauer et al. 2020; Krotov and Hopfield 2016). We also vary the iteration number for the first stage in Algorithm 1. We use MNIST, CIFAR10 datasets for this task. Please see Appendix F for experimental details.
This experiment follows the same procedure as the memory capacity tasks, but with multiple levels of injected noise on the target image instead of masking out pixels to generate queries. We use Gaussian noise to contaminate the queries and vary the noise level by altering the mean of the Gaussian vectors. As the noise level increases, it becomes more difficult to retrieve the memory with low error. A higher noise level results in greater difficulty in achieving low-error retrieval. We use MNIST, CIFAR10 for this task. Please see Appendix G for experimental details.
We set across all the memory retrieval experiments. For the evaluation metric, we follow (Hu et al. 2023; Millidge et al. 2022) to use the Sum-of-Square pixel differences between the ground truth image and the retrieved image.
See Figure 3 for results of memory capacity and noise robustness, Figure 5 for results of “Stage I iteration improve retrieval error” and Section G.1 for the relationship between separation loss and retrieval error.
For memory capacity, outperforms all other baselines by a large margin. This result shows the retrieval dynamics under is near optimal across all memory set sizes. Next, we vary the iteration to observe how fast the retrieval error decreases as the goes up. In Figure 5, we show a strong correlation between and retrieval error.
For noise robustness, shows strong performance against all baselines as well as showed in Figure 3.
2 Supervised Learning Tasks
For classification tasks, we compare our method against (Ramsauer et al. 2020) and (Hu et al. 2023). We test two settings:
+ Dense Modern Hopfield Model (Ramsauer et al. 2020), and
+ Sparse Modern Hopfield Model (Hu et al. 2023).
We vary the training sample size and observe model performance. We focus on (i) convergence speed (speed of loss decay), (ii) generalization power (test accuracy). We use CIFAR10, CIFAR100 and TinyImageNet for this task. Please see Appendix F for more experimental details.
We use the following layer (Ramsauer et al. 2020) to replace the self-attention mechanism in Vision Transformer:
To verify Theorem 3.1, we evaluate how many samples a model can memorize in supervised learning task. We follow the image classification settings, and see how Hopfield models with and without react to sample size growth.
We also use the (Wu et al. 2024) as our test-bed and observe the performance change with and without . For this task, we use ETTh1, ETTm1 and WTH datasets. We use the prediction horizon of for all datasets. Please see Appendix F for experimental and hyperparameter details.
We compare the performance of Modern Hopfield and Sparse Hopfield with and without . For image classification, we use Vision Transformer (Dosovitskiy et al. 2020) as test-bed and replace the attention mechanism with (Ramsauer et al. 2020) and layer (Hu et al. 2023). For time series prediction, we compare the performance of (Hu et al. 2023) with and without .
See Table 1 for convergence results of image classification task, Figure 6 for expressiveness results (Theorem 3.1) and Table 8 for time series prediction.
For image classification, we observe that modern Hopfield models under consistently outperform other baselines, and the performance gap increases with the sample size growth. Additionally, models shows superior convergence speed comparing to other baselines on both training and test set. For model generalization, see Table 1, for convergence results, see Section G.5.
For model expressiveness, we observe that when the dataset size is small, has similar memorization capability as . However, as the dataset size increases, without shows a sharp degeneration on training accuracy and struggles to converge well, as evidenced in Figure 6. For more detailed results, see Section G.4.
For time series prediction, our results (in Section G.6) demonstrate that even on SOTA Hopfield-based time series model, delivers performance improvement across different datasets and prediction horizons.
3 More Discussions on Experimental Results
For memory retrieval tasks, delivers significant improvements on retrieval error by lowering separation loss over the memory set. For the epochs required for kernel learning, we demonstrate that low retrieval error has strong correlation with large size of . This is expected as our separation loss is convex and guaranteed to obtain global optima with a rate of . As showed in Figure 5, separation loss consistently decreased as goes up.
For classification tasks, delivers significant improvements in predictive power of the underlying models. Comparing to contrastive self-supervised learning (Wang and Isola 2020; Chen et al. 2020), where they maximize pairwise distance between samples, maximizes the pairwise distance between patches. As Saunshi et al. 2022 show maximizing the distance over samples improves class generalization and is beneficial to downstream tasks.
Our experiment results indicate 2 new insights that the separation on the patch/token level also leads to better generalization. Firstly, we hypothesize that the Stage I of serves as a pre-training step for a better representation with more separated data geometry. Namely, tokens/patches projected to kernel space have higher quality of representation as ’s first iteration leads to better patch separation. Secondly, though “ layers with and without ” and “expressiveness” experiments (Table 1 and Figure 6), we observe that solely increasing embedding dimension do not guarantee to escape from the low-rank bottleneck in attention- and Hopfield-based models (Bhojanapalli et al. 2020). We conclude that this is because these models do not utilize their full expressive power (as in Theorem 3.1), despite of high embedding dimension. This observation supplements the existing “high-dimensional embedding improves low-rank bottleneck” conjecture (Bhojanapalli et al. 2020) with an intuitive yet effective learning scheme.
Concluding Remarks
Algorithm 1 has a time complexity of . Algorithm 2 has a time complexity of . Although this increases the standard supervised learning training time by a factor of , our experimental results demonstrate that models under mitigate this issue with a faster convergence speed, requiring fewer epochs to converge. See Section G.5 for related empirical results.
One notable limitation is that the optimality of separation loss (Definition 2.2) does not guarantee maximal separation for for any given . This problem (maximizing ) is inherently a max-min (non-convex) problem and is less straightforward to analyze (Comparison between max and avg. loss is in Section G.2). To achieve provably optimal memory capacity, we plan to explore different loss functions or learning schemes in the future.
To address the above limitation, the follow-up work (Hu et al. 2024d) presents a provably optimal memory capacity bound for kernelized modern Hopfield models and introduces a sub-linear time algorithm, +, to achieve this optimal capacity.
Impact Statement
This research is theoretical and is not expected to have negative social impacts. As outlined in the introduction and related works, the primary goal of this study is to enhance our understanding of the underlying principles of large Hopfield-based and transformer-based foundation models from an associative memory perspective.
Acknowledgments
JH would like to thank Stephen Cheng, Shang Wu, Dino Feng and Andrew Chen for enlightening discussions, the Red Maple Family for support, and Jiayi Wang for facilitating experimental deployments. The authors would also like to thank the anonymous reviewers and program chairs for their constructive comments.
JH is partially supported by the Walter P. Murphy Fellowship. HL is partially supported by NIH R01LM1372201, NSF CAREER1841569, DOE DE-AC02-07CH11359, DOE LAB 20-2261 and a NSF TRIPODS1740735. This research was supported in part through the computational resources and staff contributions provided for the Quest high performance computing facility at Northwestern University which is jointly supported by the Office of the Provost, the Office for Research, and Northwestern University Information Technology. The content is solely the responsibility of the authors and does not necessarily represent the official views of the funding agencies.
Supplementary Material
Section D. Supplementary Theoretical Backgrounds
Appendix B Related Work
Associative memory models (Willshaw et al. 1969; Kanerva 1988) have been widely discussed in both the neuroscience and machine learning fields. The main goal of these models are to store a set of memory patterns where those patterns can be retrieved with respect to a given query. Hopfield models represent a primary category within the class of computational associative memory models (Hopfield 1982). Starting from the classical Hopfield models (Hopfield 1982; Hopfield 1984; Krotov and Hopfield 2021), these models are able to store and retrieve binary patterns with guaranteed memorization capacity. Their biologically plausible designs provides significant insights to understand both human brains (Yampolskaya and Mehta 2023; Krotov and Hopfield 2021) and modern deep learning paradigms (Burns 2024; Cabannes et al. 2024b; Cabannes et al. 2024a; Kozachkov et al. 2023; Negri et al. 2023; Ramsauer et al. 2020). Recently, these Hopfield models regain interest in the deep learning field due to its connection to the attention mechanism in transformers. Notably, Ramsauer et al. 2020 propose the Modern Hopfield models (MHMs) whose single-step update is equivalent to the attention mechanism (Vaswani et al. 2017). As a result, this connection (starting from the dense associative memory model (Krotov and Hopfield 2016)) facilitates the integration of associative memory models into modern deep learning (Hofmann et al. 2024; Hu et al. 2024b; Xu et al. 2024; Wu et al. 2024; Burns and Fukai 2023; Auer et al. 2024; Widrich et al. 2020) and large foundation models (Hu et al. 2024a; Pan et al. 2024; Fürst et al. 2022).
Beside empirical success, Modern Hopfield Models (MHM) offer a low-assumption theoretical framework for analyzing transformer-based deep learning architectures. Toward their fundamental theory, Hu et al. 2023 and Wu et al. 2024 point out that the energy function of MHM and its sparse variants are actually tied to the convex conjugates of different entropic regularizers. This has led to the Sparse and Generalized Sparse HMHs, which are connected to attention mechanisms with various degrees of sparsity (Correia et al. 2019; Vaswani et al. 2017; Martins and Astudillo 2016). Extending this foundation, Hu et al. 2024b further complement this understanding with the principled construction of possible efficient variants from a nonparametric perspective. Furthermore, Hu et al. 2024c provide a detailed theoretical analysis of all possible efficient variants, through the lens of fine-grained complexity theory.
We would like to comment further on the results of (Hu et al. 2024c). First, it observes that the magnitude of the patterns (i.e., the norms of queries and memories) not only affects retrieval accuracy (as seen in the linear scaling in (1.3)), but also determines the efficiency of a variant of the modern Hopfield model. This norm-based efficiency criterion, with precision guarantees, echoes the outlier effect in the attention heads of transformer models (Hu et al. 2024a). This outlier effect is well-known in pretraining large transformer-based models for its negative impact on model quantization performance (Sun et al. 2024; Bondarenko et al. 2023; Bondarenko et al. 2021). To address this, Hu et al. 2024a interpret the outlier effect as inefficient rare memory retrieval and propose the outlier-efficient Hopfield layer for transformer-based large models, demonstrating strong empirical performance and theoretical guarantees. The benefits of removing outliers in the attention heads of transformer-based large foundation models are also highlighted in (Gu et al. 2024a; Gu et al. 2024b; Alman and Song 2024a; Alman and Song 2024b; Alman and Song 2023; Gao et al. 2023) from various theoretical perspectives. In this work, the removal of outliers is achieved by the row-wise normalization in (see line 4 of Algorithm 1).
Another line of research focuses on learning an associative memory model (Tyulmankov et al. 2021; Salvatori et al. 2021) that has the ability to “read” (retrieve) and “write” (store) memories. Particularly, this type of method contains a ”readout” network to retrieve/generate memories with a given query. Bartunov et al. 2019 propose a meta learning framework to learn a generative network that treats the retrieval error as their energy function. Yoo and Wood 2022 propose a hierarchical associative memory model that relaxes the requirement of meta learning. Salvatori et al. 2021 propose a hierarchical generative network trained with predictive coding. Instead of deriving the retrieval dynamics from the energy function, these methods normally use a generative model for memory retrieval. With the expressiveness of deep neural networks, such method showed great empirical performances. However, since the structure of the readout network does not connect or dependent on the energy function, they are not able to preserve appealing theoretical guarantees like Hopfield models.
Iatropoulos et al. 2022 propose a kernelized memory network In a similar vein, Schaeffer et al. 2024 bridge associative memory models and probabilistic modeling. . They formulate the modern Hopfield models with a recurrent SVM model. In particular, their kernel is a single layer feed forward network that is trained to memorize patterns. However, their framework consists of several high assumptions. In comparison, our proposed framework has mild assumption on parameters and pattern distributions. In addition, has significant practical usage and was validated through extensive experiments in both memory retrieval and supervised learning tasks.
This work bridges two paradigms of associative memory models via a non-singular kernel, such that the kernelized energy function (2.2) still satisfies the defining properties of modern Hopfield models, i.e. attention-included retrieval dynamics (Theorem 2.1). A comparison between Uniform Memory Hopfield and similar models are shown in Table 3.
The usage of kernels and feature expansions in transformers has been extensively discussed in previous literature. One primary objective of these studies is to reduce the computational complexity associated with attention mechanisms. For instance, Chen et al. 2021b; Kitaev et al. 2020; Chen et al. 2021a demonstrate empirically and theoretically that these efficient algorithms can effectively approximate SoftMax attention. Song et al. 2021 provides a generalized framework for attention mechanism by decomposing it into two parts, RBF kernel as similarity measure and norm weighting on tokens. In our paper, we offer a distinct perspective aimed at enhancing memory capacity, drawing inspiration from the construction of the modern Hopfield model. Therefore, our approach differs from attempting to approximate the standard modern Hopfield association. Instead, we focus on relocating memory patterns to facilitate easier retrieval.
Appendix C Connection to Transformer Attentions
Suppose that and are embedded from the raw query and memory patterns, respectively, via , and , with some projection matrices and . Then, taking the transport of in (1.2) and multiplying with such that , we obtain
This result enables that the modern Hopfield models are able to serve as powerful alternatives to the attention mechanism equipped with additional functionalities.
Appendix D Supplementary Theoretical Backgrounds
Here we quote some known results from (Hu et al. 2023; Martins and Astudillo 2016).
The variational form of is defined by the optimization problem
where is the Tsallis entropic regularizer given by (D.2).
D.2 Separation Loss
With the output vector of is normalized, we have
D.3 Convergence Rate of Gradient Descent
where is the optimal value of . Intuitively, this means that gradient descent is guaranteed to converge and that it converges with rate .
we must run iterations of gradient descent, which gives us a sub-linear
Appendix E Proofs of Main Text
Here we introduce a helper lemma from (Sriperumbudur and Lanckriet 2009, Lemma 5).
Following Theorem 2.1, is called the fixed point of iteration w.r.t. if and is considered as a generalized fixed point of if . If is a generalized fixed point of , then, is a stationary point of the energy minimization problem in Equation 2.2.
Based on Zangwill’s global convergence theory (Zangwill 1969), a set of limit points of are all generalized fixed points if the retrieval dynamics and energy function satisfies the following conditions:
For any sequence with as starting point, all points in are in the compact set .
is monotonically decreased by , where .
For all , if , is closed at .
From Definition 2.1, since radius is bounded and closed, is a compact set. Thus satisfies the first condition. CCCP (Yuille and Rangarajan 2001) studied the monotonic decreasing property. With our definition of , we have is continuous in . As a result, by (Hu et al. 2023, Lemma E.1), condition (iii) holds due to the non-empty assumption on the point-to-set map . Thus, by Zangwill’s global convergence theory, all limit points are also the stationary points of the energy minimization problem in (2.2). By the results in Lemma E.1, these fixed points are also the stationary points of the minimization problem. Thus, (2.2) is guaranteed to converge to local minimum. ∎
E.2 Proof of Theorem 2.1
Since the function is non-decreasing and convex, and is convex, the composited function is convex. Thus, the energy function is the sum of a convex function: and a concave function: .
Therefore, we have . With the Concave-Convex Procedure (CCCP) (Yuille and Rangarajan 2001), the energy function is guaranteed to monotonically decrease the energy as a function of time with the following update rule:
E.3 Proofs of Theorem 2.2 and Corollary 2.2.1
Here we use the same proof strategy in (Martins et al. 2023, Proposition 2).
If we have exact memory retrieval of pattern , the following equation holds:
This is also equivalent to itself being the fixed point.
With the assumption of normalized patterns, we are able to reduce the above condition to
E.4 Proof of Theorem 3.1
By construction, any two columns in satisfies:
With , and using (E.4), we obtain
As a result, to construct and such that they satisfy Theorem 3.1, any two matrices must satisfy
Appendix F Implementation Details
MNIST. It is a hand written digits image recognition dataset (LeCun et al. 1998) consists of 60000 training samples and 10000 test samples. Each image has the size of . The label contains digits from 0 to 9.
CIFAR10. It is an image recognition dataset (Krizhevsky et al. 2009) consists of 50000 training samples and 10000 test samples. Each image has the size of . The dataset contains 10 categories with 6000 samples for each.
CIFAR100. It is an image recognition dataset (Krizhevsky et al. 2009) consists of 50000 training samples and 10000 test samples. Rach image has the size of . The dataset contains 100 categories with 600 samples for each.
TinyImageNet. It is an image recognition dataset (Le and Yang 2015) contains 100000 images of 200 classes. Each image is downsized to 64×64 colored images. Each class has 500 training images, 50 validation and test images.
ETT (Electricity Transformer Temperature). ETT (Zhou et al. 2021) records 2 years of data from two counties in China. We use two sub-datasets: ETTh1 (hourly) and ETTm1 (every 15 minutes). Each entry includes the “oil temperature” target and six power load features.
WTH (Weather). WTH records climatological data from approximately 1,600 U.S. sites between 2010 and 2013, measured hourly. Entries include the “wet bulb” target and 11 climate features.
F.2 Memory Capacity
For memory capacity experiment, we follow the settings in (Hu et al. 2023; Wu et al. 2024).
We randomly mask of the pixels in the image, using the masked image as a query for a single-step update with various Hopfield models. In the case of , we trained the kernel with different numbers of epochs on the memory set and then used it for memory retrieval. We reported the sum-of-square pixel difference between the retrieved image and the ground truth. In each run, we repeated this process for every image in the memory set, conducting the experiment 20 times for each baseline. The range of kernel learning epochs, memory set size can be found in Table 4. For Figure 26, we use for MNIST and for CIFAR10.
F.3 Noise Robustness
For noise robustness experiment, we follow the settings in (Hu et al. 2023; Wu et al. 2024).
For the noise robustness experiment, we randomly sampled a Gaussian noise vector for each image, varying the norm of the sampled noise to adjust the noise level. We then added the noise to the query image and performed a single-step update with different Hopfield models. For , we trained the kernel with N iterations on the memory set and then used it for memory retrieval. We set for MNIST and for CIFAR10. We reported the sum-of-square pixel difference between the retrieved image and the ground truth. In each run, we repeated this process for every image in the memory set, conducting the experiment 20 times for each baseline.
F.4 Classification
CIFAR10 and CIFAR100. For these two datasets, we consider four different Hopfield layers as encoder:
(Ramsauer et al. 2020)
(Hu et al. 2023)
+
+ .
We use a fully connected layer right after the encoder for classification. For each image, we follow the same process as introduced in (Dosovitskiy et al. 2020). We split an image into patches and add an additional patch for classification. We send patches into the layer with the patch as query and other patches as memory. We then send the output to a fully connected layer for prediction. We use the CrossEntropy loss and Adam optimizer for training. Hyperparameters are in Table 5.
Tiny ImageNet. For this dataset, we use a 3 layered Vision Transformer as backbone (Dosovitskiy et al. 2020), and use variations to replace attention mechanism in . Other processes are the same as introduced in the above paragraph. For kernel learning, we learn all kernels in different layers by passing a full forward pass. We then send the output to a fully connected layer for prediction. Hyperparameters are in Table 6.
F.5 Hopfield-Based Time Series Prediction with STanHop-Net (Wu et al. 2024) (Table 8)
For this task, we use STanHop-Net (Wu et al. 2024) as backbone, and equip it with . In addition, we use Algorithm 2 to minimize both separation loss and the MAE loss. For prediction horizon of , we use one layered STanHop-Net, for , we use a two layered STanHop-Net. We use the same settings for with and without We thank the authors of (Reneau et al. 2023) for their helpful comments on this part..
Appendix G Additional Numerical Experiments
This section is a visualization of relationship between separation loss and retrieval error on MNIST and CIFAR10. The result shows that the retrieval error is highly correlated with respect to the value separation loss.
G.2 Max. Loss v.s. Avg. Loss
In the main paper, we discuss the differences between minimizing the maximum separation loss and the average separation loss.
Ideally, minimizing the maximum separation loss directly contributes to . However, as stated in the main text, such a loss is a max-min problem, which is challenging to optimize. Moreover, it entails an additional quadratic time complexity due to the max operation. On the other hand, the average loss is more time-efficient. It is also convex, thereby guaranteeing convergence to the global optimum at a rate of under gradient descent, where is the number of iterations. However, the average loss does not guarantee maximizing , nor does it ensure an optimal for any . Therefore, its theoretical impact on memory capacity and retrieval error bound is difficult to quantify.
As a result, we conduct an analysis comparing the performance of each loss function. We vary the memory size and the kernel learning iteration and perform memory retrieval on MNIST and CIFAR10 datasets.
The results demonstrate that minimizing the average loss yields a lower retrieval error, and this advantage grows with the size of the memory set. Additionally, the retrieval error decreases more rapidly with respect to under average loss than under maximum loss. This outcome is anticipated, as minimizing the maximum loss is a non-convex problem and does not guarantee reaching global optima. This empirical finding indicates that in practice, minimizing the average loss leads to better efficiency and retrieval outcomes.
We observe that with the average loss, achieves almost perfect retrieval outcomes with . However, using the maximum loss struggles to reach its global minimum during optimization, thus hindering its ability to achieve optimal memory capacity. This is observed in Figure 8.
With CIFAR10 being more difficult comparing to MNIST, under average loss still outperforms under Max. loss.
G.3 Memory Retrieval
Here we again show the memory retrieval results with higher resolution. The result demonstrates with , modern Hopfield models obtain significant improvement on both datasets.
G.4 Model Expressiveness
Here we present the model expressiveness on training data. This is a empirical validation for Theorem 3.1. We observe that without , baseline models suffer from sharp performance drop, which also lead to generalization degradation as show in Section G.5.1. In contrast, with , models show better robustness against sample size increase.
G.5 Classification
Here we conduct empirical analysis on the correlation between dataset size and model convergence. In general, it is more difficult to memorize all samples for larger dataset. However, learning from more samples might lead to a better generalization performance, results in higher test accuracy.
The result demonstrates significantly improves model’s performance on 3 aspects:
The improvement also became more obvious when the dataset size increases. This is reasonable as the standard layer is powerful enough to memorize small sample size with and without .
The model behavior was similar comparing to what we observe from CIFAR10. The performance improvement under became stronger with the increase of dataset size. With , the model improves on both convergence speed, memorization capacity (training accuracy) and generalization power (test accuracy).
Models under continue to show strong performance against baselines on Tiny ImageNet dataset. Notably, we use a 3 layer encoder for this dataset, which provides additional insights ensuring that works well under deep neural network architecture.
G.6 Time Series Prediction
Here we report the results of our time series prediction experiment. From Table 8, we observe that obtains improvement in most datasets and prediction horizons.