Rectified Lagrangian for Out-of-Distribution Detection in Modern Hopfield Networks
Ryo Moriai, Nakamasa Inoue, Masayuki Tanaka, Rei Kawakami, Satoshi Ikehata, Ikuro Sato
TL;DR
This work tackles the challenge of detecting out-of-distribution data in modern Hopfield networks by introducing Rectified Lagrangian (RecLag), a modified memory Lagrangian that creates an explicit OOD attractor while preserving the MHN framework. The authors prove theoretical guarantees including a trivial origin attractor for any interaction matrix and reduction to vanilla MHNs in the high memory-strength limit, and they train the interaction via probabilistic, SFNN-like mechanisms to estimate in-distribution densities. They further show that data with low probability under a derived joint distribution p_H fall into the OOD attractor, enabling density-based OOD detection, and demonstrate superior performance against energy-based baselines across nine image datasets. The approach offers a principled, post-hoc OOD detector for MHNs with tunable sensitivity via the inverse memory-strength parameter and potential for broader applicability to structured or hierarchical memory patterns.
Abstract
Modern Hopfield networks (MHNs) have recently gained significant attention in the field of artificial intelligence because they can store and retrieve a large set of patterns with an exponentially large memory capacity. A MHN is generally a dynamical system defined with Lagrangians of memory and feature neurons, where memories associated with in-distribution (ID) samples are represented by attractors in the feature space. One major problem in existing MHNs lies in managing out-of-distribution (OOD) samples because it was originally assumed that all samples are ID samples. To address this, we propose the rectified Lagrangian (RegLag), a new Lagrangian for memory neurons that explicitly incorporates an attractor for OOD samples in the dynamical system of MHNs. RecLag creates a trivial point attractor for any interaction matrix, enabling OOD detection by identifying samples that fall into this attractor as OOD. The interaction matrix is optimized so that the probability densities can be estimated to identify ID/OOD. We demonstrate the effectiveness of RecLag-based MHNs compared to energy-based OOD detection methods, including those using state-of-the-art Hopfield energies, across nine image datasets.
