{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/hopfield-networks-is-all-you-need","title":"Hopfield Networks is All You Need","arxiv_id":"2008.02217","date":"2020-07-16","proceeding":"ICLR 2021 1","authors":["Hubert Ramsauer","Bernhard Schäfl","Johannes Lehner","Philipp Seidl","Michael Widrich","Thomas Adler","Lukas Gruber","Markus Holzleitner","Milena Pavlović","Geir Kjetil Sandve","Victor Greiff","David Kreil","Michael Kopp","Günter Klambauer","Johannes Brandstetter","Sepp Hochreiter"],"abstract":"We introduce a modern Hopfield network with continuous states and a corresponding update rule. The new Hopfield network can store exponentially (with the dimension of the associative space) many patterns, retrieves the pattern with one update, and has exponentially small retrieval errors. It has three types of energy minima (fixed points of the update): (1) global fixed point averaging over all patterns, (2) metastable states averaging over a subset of patterns, and (3) fixed points which store a single pattern. The new update rule is equivalent to the attention mechanism used in transformers. This equivalence enables a characterization of the heads of transformer models. These heads perform in the first layers preferably global averaging and in higher layers partial averaging via metastable states. The new modern Hopfield network can be integrated into deep learning architectures as layers to allow the storage of and access to raw input data, intermediate results, or learned prototypes. These Hopfield layers enable new ways of deep learning, beyond fully-connected, convolutional, or recurrent networks, and provide pooling, memory, association, and attention mechanisms. We demonstrate the broad applicability of the Hopfield layers across various domains. Hopfield layers improved state-of-the-art on three out of four considered multiple instance learning problems as well as on immune repertoire classification with several hundreds of thousands of instances. On the UCI benchmark collections of small classification tasks, where deep learning methods typically struggle, Hopfield layers yielded a new state-of-the-art when compared to different machine learning methods. Finally, Hopfield layers achieved state-of-the-art on two drug design datasets. The implementation is available at: https://github.com/ml-jku/hopfield-layers","url_abs":"https://arxiv.org/abs/2008.02217v3","url_pdf":"https://arxiv.org/pdf/2008.02217v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"hopfield-networks-is-all-you-need","repo_url":"https://github.com/ml-jku/hopfield-layers","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":null},{"paper_slug":"hopfield-networks-is-all-you-need","repo_url":"https://github.com/ml-jku/mhn-react","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"NOASSERTION"}},{"paper_slug":"hopfield-networks-is-all-you-need","repo_url":"https://github.com/ppsp-team/pyhkbs","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok","spdx":"BSD-3-Clause"}}],"tasks":[{"task_slug":"all","task_name":"All"},{"task_slug":"drug-design","task_name":"Drug Design"},{"task_slug":"immune-repertoire-classification","task_name":"Immune Repertoire Classification"},{"task_slug":"multiple-instance-learning","task_name":"Multiple Instance Learning"},{"task_slug":"retrieval","task_name":"Retrieval"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"attention-dropout","method_name":"Attention Dropout"},{"method_slug":"bert","method_name":"BERT"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"hopfield-layer","method_name":"Hopfield Layer"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"linear-warmup-with-linear-decay","method_name":"Linear Warmup With Linear Decay"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"},{"method_slug":"weight-decay","method_name":"Weight Decay"},{"method_slug":"wordpiece","method_name":"WordPiece"}],"datasets_introduced":[],"methods_introduced":[{"slug":"hopfield-layer","name":"Hopfield Layer","full_name":"Hopfield Layer"}],"results":[],"syntology":{"syntology_url":"https://syntology.ai/paper/2008.02217","atlas_url":"https://app.syntology.ai/?focus=2008.02217","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2008.02217"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-25T09:33:49+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ppsp-team/pyhkbs","reach":{"status":"ok","spdx":"BSD-3-Clause"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ml-jku/mhn-react","reach":{"status":"ok","spdx":"NOASSERTION"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/ml-jku/hopfield-layers","reach":null}],"summary":{"ran":8,"unverified":1},"by_repo_kind":{"listed":{"samples":9,"ran":8,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"7d6c1bc2b71b84af","entry":"HKBextended","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"basicHKB.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/basicHKB.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"7d6c1bc2b71b84af"}},{"code_sha256_prefix":"d192a8b31ecb58fb","entry":"HKBextended_torch","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"basicHKB.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/basicHKB.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d192a8b31ecb58fb"}},{"code_sha256_prefix":"30b782ad6c30dce4","entry":"calculate_KOP","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"grid_search_evaluation.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/grid_search_evaluation.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"30b782ad6c30dce4"}},{"code_sha256_prefix":"ce92b635cbc158a0","entry":"calculate_average_wPLI","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"grid_search_evaluation.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/grid_search_evaluation.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"ce92b635cbc158a0"}},{"code_sha256_prefix":"d5712474eaf7a180","entry":"calculate_inter_agent_PLV","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"grid_search_social_evaluation.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/grid_search_social_evaluation.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d5712474eaf7a180"}},{"code_sha256_prefix":"7015688342676943","entry":"calculate_movement_KOP","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"grid_search_social_evaluation.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/grid_search_social_evaluation.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"7015688342676943"}},{"code_sha256_prefix":"64cac94b69ef1b11","entry":"calculate_wPLI","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"grid_search_evaluation.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/grid_search_evaluation.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"64cac94b69ef1b11"}},{"code_sha256_prefix":"d470117f2f37e57d","entry":"complementary_connection","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"grid_search_social.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/grid_search_social.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"d470117f2f37e57d"}},{"code_sha256_prefix":"ec31ea2fe93a67b9","entry":"single_simulation","repo":"ppsp-team/pyhkbs","repo_kind":"listed","path":"simulations.py","file_url":"https://github.com/ppsp-team/pyhkbs/blob/HEAD/simulations.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"BSD-3-Clause","inline_ok":true,"mcp_get_code":{"code_sha256":"ec31ea2fe93a67b9"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}