A recurrent network that stores patterns as energy minima β memory as physics.
π Where this lives: Hopfield's 1982 paper is one of the most consequential in the field, and not only for neural networks β it imported the mathematics of magnetic spin glasses from statistical physics into computing, which brought an entire physics community into AI research and directly produced the Boltzmann machine and, eventually, modern generative models. John Hopfield shared the 2024 Nobel Prize in Physics for exactly this work. Search "Hopfield network associative memory energy function spin glass".
Structure and dynamics
A HOPFIELD NETWORK IS UNLIKE EVERY NETWORK SO FAR IN THIS
SECTION, and the differences are the point:
Β· SINGLE LAYER β there is no input layer, hidden layer or
output layer. Every unit is all three at once.
Β· FULLY RECURRENT β every unit connects to every other. The
network is a cycle, not a feedforward chain.
Β· SYMMETRIC WEIGHTS β wα΅’β±Ό = wβ±Όα΅’. THIS IS ESSENTIAL, and the
reason appears below: without it there is no energy function
and no convergence guarantee.
Β· NO SELF-CONNECTIONS β wα΅’α΅’ = 0, or a unit would simply
reinforce its own state.
Β· BIPOLAR STATES β sα΅’ β {β1, +1}, as in the Hebbian topic.
Β· ASYNCHRONOUS UPDATING β one unit at a time, in random order.
sβ β· sβ
‒ Ⳡ‑ every unit connected to every other,
sβ β· sβ symmetrically
THE UPDATE RULE β the same threshold unit as always:
sα΅’ β +1 if Ξ£β±Ό wα΅’β±Ό sβ±Ό β₯ 0
sα΅’ β β1 otherwise
Units are updated one at a time until NO UNIT CHANGES on a
full sweep. That state is a STABLE STATE, and it is the
network's answer.
STORING PATTERNS β THE HEBBIAN OUTER-PRODUCT RULE, in ONE PASS
with NO ITERATION:
wα΅’β±Ό = Ξ£β xα΅’α΅ xβ±Όα΅ for i β j, wα΅’α΅’ = 0
This is Hebb's rule from earlier in the section, applied to
every pair of units and summed over the patterns. THERE IS NO
TRAINING LOOP, NO LEARNING RATE AND NO ERROR β the weights are
computed directly from the patterns. That alone makes the
Hopfield network unusual among everything else here.
A WORKED CONSTRUCTION, 4 units, 2 patterns:
pΒΉ = (1, β1, 1, β1) pΒ² = (1, 1, β1, β1)
wββ = (1)(β1) + (1)(1) = 0
wββ = (1)(1) + (1)(β1) = 0
wββ = (1)(β1) + (1)(β1) = β2
wββ = (β1)(1) + (1)(β1) = β2
wββ = (β1)(β1) + (1)(β1) = 0
wββ = (1)(β1) + (β1)(β1) = 0
W = β‘ 0 0 0 β2 β€
β’ 0 0 β2 0 β₯
β’ 0 β2 0 0 β₯
β£ β2 0 0 0 β¦
NOTE THAT THE MATRIX IS SYMMETRIC with a zero diagonal, as
required, and that several weights CANCELLED TO ZERO because
the two patterns disagree about those pairs. That cancellation
is the seed of the capacity limit discussed below.
The energy function, and a traced recall
HOPFIELD'S CENTRAL CONTRIBUTION β THE ENERGY FUNCTION, also
called the Lyapunov function:
E = βΒ½ Ξ£α΅’ Ξ£β±Ό wα΅’β±Ό sα΅’ sβ±Ό
THE THEOREM: EVERY ASYNCHRONOUS UPDATE EITHER DECREASES E OR
LEAVES IT UNCHANGED. E NEVER INCREASES.
WHY, and the argument is short enough to reproduce in an exam.
Suppose unit i flips from sα΅’ to sα΅’β². Only terms involving i
change, so
ΞE = β(sα΅’β² β sα΅’) Β· Ξ£β±Ό wα΅’β±Ό sβ±Ό = βΞsα΅’ Β· netα΅’
The update rule sets sα΅’β² = +1 exactly when netα΅’ β₯ 0. So if the
unit flips upward, Ξsα΅’ > 0 and netα΅’ β₯ 0, making ΞE β€ 0; if it
flips downward, Ξsα΅’ < 0 and netα΅’ < 0, so again ΞE β€ 0.
A FLIP IS ONLY EVER MADE IN THE DIRECTION THAT LOWERS THE
ENERGY. And since there are finitely many states (2^N), E is
bounded below and must reach a minimum in finite time.
THIS IS WHY SYMMETRY IS REQUIRED: the cancellation in ΞE
depends on wα΅’β±Ό = wβ±Όα΅’. With asymmetric weights E is not a
Lyapunov function and the network can OSCILLATE FOREVER.
THE PICTURE THAT MAKES IT INTUITIVE:
The energy function defines a LANDSCAPE over the 2^N possible
states. STORED PATTERNS ARE THE VALLEYS. An input state
places a ball somewhere on that landscape, and the update
rule rolls it downhill until it settles.
RECALL IS THEREFORE RELAXATION TO THE NEAREST MINIMUM β and
this is what makes the memory CONTENT-ADDRESSABLE: you
retrieve a pattern by supplying a corrupted or partial
version of the pattern itself, not an address. THE BASIN OF
ATTRACTION around each stored pattern is what gives the
network its error tolerance.
A TRACED RECALL, with the weights computed above.
Present the corrupted state s = (1, β1, β1, β1) β this is
pattern pΒ² = (1, 1, β1, β1) with the second bit flipped.
E(start) = 0
unit 0: net = wββsβ = (β2)(β1) = +2 β₯ 0 β sβ = +1, STABLE
unit 1: net = wββsβ = (β2)(β1) = +2 β₯ 0 β sβ = +1, FLIPS
state β (1, 1, β1, β1) E = β4
unit 2: net = wββsβ = (β2)(1) = β2 < 0 β sβ = β1, STABLE
unit 3: net = wββsβ = (β2)(1) = β2 < 0 β sβ = β1, STABLE
SWEEP 2: every unit is stable, so the network has converged.
RESULT: (1, 1, β1, β1) = pΒ² EXACTLY, RECOVERED FROM A
CORRUPTED INPUT, and the energy fell from 0 to β4, which is
the same energy as the stored patterns.
THAT IS ASSOCIATIVE MEMORY IN EIGHT LINES OF ARITHMETIC: a
damaged input, a downhill walk, and the original pattern
restored.
Capacity, spurious states, and what came after
THE STORAGE CAPACITY β the network's principal limitation, and a
guaranteed exam question:
P_max β 0.138 N (often quoted as 0.15N)
where N is the number of units. THE RESULT IS BRUTAL:
N = 100 units β about 13 patterns, using 4,950 weights
N = 1,000 units β about 138 patterns, using 499,500 weights
HALF A MILLION WEIGHTS TO STORE 138 PATTERNS. The capacity
grows LINEARLY in N while the weight count grows
QUADRATICALLY, so the network becomes less efficient the
larger it gets β which is why Hopfield networks are studied
for their ideas rather than deployed as storage.
AND EXCEEDING THE LIMIT DOES NOT DEGRADE GRACEFULLY. Beyond
β0.138N the memory undergoes a sudden collapse β a PHASE
TRANSITION, in the physics sense β and recall of ALL patterns
fails, not just the newest. This is called CATASTROPHIC
FORGETTING, and the mechanism is visible in the worked
construction above: conflicting patterns cancel each other's
weights until nothing coherent remains.
THE PATTERNS ALSO NEED TO BE NEAR-ORTHOGONAL. Similar patterns
interfere strongly, so the practical capacity for correlated
data is far below the theoretical figure.
SPURIOUS STATES β stable states that were never stored:
1. THE INVERSE OF EVERY STORED PATTERN is always stable,
because E depends on products sα΅’sβ±Ό and flipping every
sign leaves them unchanged. In the worked example,
E(βpΒΉ) = β4, identical to E(pΒΉ). YOU CANNOT AVOID THIS β
it is a structural consequence of the energy function.
2. MIXTURE STATES β combinations of odd numbers of stored
patterns, such as sign(pΒΉ + pΒ² + pΒ³), are often stable.
3. SPIN-GLASS STATES β local minima with no relation to any
stored pattern, which multiply as the capacity limit is
approached.
MITIGATIONS: unlearning (running the network freely and
applying anti-Hebbian updates to whatever it settles into),
and stochastic updating, which lets the network escape shallow
spurious minima.
DISCRETE VERSUS CONTINUOUS:
The DISCRETE model above uses binary/bipolar states and
asynchronous updates, and is used for associative memory.
The CONTINUOUS model (Hopfield 1984) uses sigmoid units
evolving by differential equations, and is used for
OPTIMISATION β most famously an approximate solution to the
Travelling Salesman Problem, by encoding the tour cost as
the energy function so that relaxation to a minimum
corresponds to finding a short tour. IT DOES NOT BEAT
SPECIALISED TSP SOLVERS, but the technique β cast the
problem as an energy function and let a network descend it β
is a genuinely general idea.
WHAT CAME AFTER, since the Hopfield network's importance is
mostly in what it started:
Β· BOLTZMANN MACHINE β a Hopfield network with STOCHASTIC
units, so it can escape local minima by occasionally
moving uphill (simulated annealing). Its restricted form,
the RBM, was used for the layerwise pre-training that
launched the deep learning revival around 2006.
Β· BIDIRECTIONAL ASSOCIATIVE MEMORY (BAM) β the two-layer
heteroassociative version.
Β· MODERN HOPFIELD NETWORKS (2020) β a continuous
reformulation with EXPONENTIAL rather than linear
capacity, and the striking result that its update rule is
mathematically EQUIVALENT TO THE ATTENTION MECHANISM in
transformers. The 1982 model turns out to describe part of
the architecture behind today's language models.
THE COMPARISON THAT CLOSES THE SECTION:
FEEDFORWARD (MLP) HOPFIELD
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
connections one direction FULLY RECURRENT,
symmetric
layers input/hidden/output ONE β every unit is all
three
learning BACKPROPAGATION, HEBBIAN OUTER PRODUCT,
iterative ONE PASS
operation one forward pass ITERATE TO A STABLE STATE
what it does maps inputβoutput COMPLETES a corrupted
pattern
guarantee none CONVERGENCE, via the
energy function
addressing by input CONTENT-ADDRESSABLE
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
THE ROW THAT MATTERS MOST IS THE LAST BUT ONE. A feedforward
network offers no guarantee that training converges anywhere
useful; the Hopfield network GUARANTEES that recall
terminates, because it is descending a bounded function. It
buys that guarantee with symmetric weights and a capacity of
0.138N β WHICH IS THE TRADE-OFF THE WHOLE MODEL IS BUILT ON.
Hopfield's idea in one sentence: define an energy function that the update rule can only ever decrease, and memory becomes physics β stored patterns are valleys, recall is rolling downhill, and convergence is guaranteed rather than hoped for. The price is symmetric weights and a capacity of only 0.138N.
π Go further: The most surprising development in this topic is recent. In 2020 researchers showed that a continuous "modern Hopfield network" has exponential storage capacity instead of 0.138N, and β the striking part β that its single-step update rule is mathematically identical to the attention mechanism used in transformers. So when a language model attends over its context, it is provably performing Hopfield-style associative retrieval: the query is the corrupted pattern, the stored keys are the memories, and attention is the relaxation step. A 1982 model of magnetic materials turns out to describe the core operation of the architecture behind modern AI. Search "Hopfield networks is all you need attention associative memory".
π‘ Exam angle: describe the structure precisely β single layer, fully recurrent, symmetric weights, zero diagonal, bipolar states, asynchronous updates β and be ready to say why symmetry is required. Give the Hebbian storage rule wα΅’β±Ό = Ξ£β xα΅’α΅xβ±Όα΅ and stress that it is one pass with no iteration. Write the energy function E = β½ΣΣwα΅’β±Όsα΅’sβ±Ό and show that ΞE = βΞsα΅’Β·netα΅’ β€ 0, which proves convergence. Be able to construct a small weight matrix and trace a recall from a corrupted pattern, quoting the energy at each step. Quote the capacity 0.138N, explain that failure past it is a sudden collapse rather than gradual decay, and list the spurious states β especially that the inverse of every stored pattern is always stable.
Syllabus points
Hopfield net; associative memory
Create a free account to tick topics off, take notes as you read, watch the video lessons and get a day-by-day study plan built around your exam date.