Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Hopfield Networks

Hopfield networks are recurrent associative memories that recover stored patterns from noisy cues, linking energy-based retrieval to modern attention.

Hopfield networks are recurrent neural networks that store patterns and recover them from incomplete or corrupted inputs. They act as associative memory: part of a pattern serves as the cue for retrieving the whole. A stored memory behaves like a valley in an energy landscape, and the network's changing state settles toward a nearby valley.

John J. Hopfield introduced the model in 1982 through his work on collective computation in neural networks. "Hopfield network," "Hopfield net," and "Hopfield model" are common synonyms. The architecture belongs to the recurrent neural network family because feedback connections repeatedly update its internal state.

How Hopfield Networks Store and Retrieve Patterns#

A classical Hopfield network contains interconnected neurons whose states are commonly represented as −1 or +1. Its model weights are symmetric: the connection from neuron A to neuron B equals the connection from B to A. Standard configurations set self-connections to zero. Hebbian learning stores patterns by strengthening connections between neurons whose states agree across the stored examples. Computationally, this adds each pattern's outer product—a matrix of pairwise products—to the weight matrix.

During retrieval, each neuron sums its weighted inputs and applies a threshold activation function. Asynchronous updating changes one neuron at a time. With symmetric weights, zero self-connections, and unchanged states at exact threshold ties, each state change lowers an energy function until the network reaches a stable configuration. This configuration is an attractor; the starting states that converge to it form its basin of attraction. Simultaneously updating all neurons can produce oscillations between configurations.

Storage and retrieval are separate operations. Storage changes the connections; retrieval changes neuron states while keeping those connections fixed. This makes retrieval a form of state optimization, rather than another round of backpropagation.

Pattern Recovery in Python#

The following PyTorch example stores one binary pattern using the Hebbian rule, flips two entries, and retrieves the memory through asynchronous updates.

import torch

memory = torch.tensor([1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0])
weights = torch.outer(memory, memory) / memory.numel()
weights.fill_diagonal_(0)

state = memory.clone()
state[[1, 6]] *= -1
initial_errors = int((state != memory).sum())

while True:
    previous = state.clone()
    for i in range(state.numel()):
        field = weights[i] @ state
        # Preserve the current state when the weighted input is zero.
        if field != 0:
            state[i] = field.sign()
    if torch.equal(state, previous):
        break

print(f"Bit errors: {initial_errors} -> {int((state != memory).sum())}")

The output is Bit errors: 2 -> 0: recurrent updates reconstruct the stored pattern from its corrupted cue using the standard associative-memory dynamics.

Continuous Networks, Attention, and Applications#

Continuous Hopfield networks use graded neuron outputs, such as a sigmoid, and evolve toward equilibrium. Hopfield established this formulation in 1984. Modern Hopfield networks extend associative memory with different energy functions and higher storage capacities; their continuous-state variants operate on real-valued vectors.

Hubert Ramsauer and colleagues connected modern Hopfield retrieval to attention mechanisms in 2020. A query is compared with stored vectors, softmax converts similarity scores into weights, and a weighted combination retrieves associated information. This gives the attention operation used in a transformer an associative-memory interpretation.

For image representations, Ultralytics YOLO26 exposes feature extraction through model.embed(), returning image embeddings. These vectors provide the real-valued representation used by modern associative-memory layers.

Established applications include recovering stored visual patterns, pooling large collections of features, and constrained optimization. Hopfield and David Tank applied an analog network to the traveling-salesman problem in 1985, encoding route quality and constraints into the energy landscape. Modern Hopfield pooling also supports immune-repertoire classification, aggregating information across hundreds of thousands of biological sequences through multiple-instance learning.

An autoencoder learns an encoder–decoder mapping that reconstructs inputs; a classical Hopfield network reconstructs patterns by settling into attractors. A memory bank stores representations for later access, while Hopfield dynamics specify how a cue retrieves an associated state.

Classical networks develop retrieval errors when memories interfere. Correlated patterns create cross-talk, and spurious attractors can return mixtures of stored memories. For large classical Hebbian networks storing random, approximately uncorrelated binary patterns, the familiar capacity estimate is about 0.14 times the neuron count when allowing a small fraction of retrieval errors—roughly 140 patterns for 1,000 neurons.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports
Computer vision in sports
Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery
Computer vision for aerial imagery
Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace
Computer vision in aerospace
Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security
Computer vision in security
Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics
Computer vision in robotics
Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics
Computer vision in logistics
Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail
Computer vision in retail
Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare
Computer vision in healthcare
Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing
Computer vision in manufacturing
Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive
Computer vision in automotive
Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture
Computer vision in agriculture
Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports
Computer vision in sports
Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery
Computer vision for aerial imagery
Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace
Computer vision in aerospace
Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security
Computer vision in security
Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics
Computer vision in robotics
Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics
Computer vision in logistics
Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail
Computer vision in retail
Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare
Computer vision in healthcare
Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing
Computer vision in manufacturing
Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive
Computer vision in automotive
Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture
Computer vision in agriculture
Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning