Skip to content
Guide

Graph Hopfield Networks

A Graph Hopfield Network classifies graph nodes by moving each vector in small steps. Each move points toward learned memory vectors and the node's neighbours. On Amazon's product graphs, the repeated steps carry most of the accuracy. The memory helps most when part of a node's features are masked.

Product C settles toward the cameras

Illustrative example

Four products and two memories; each bar is that product's camera weight, its resemblance to the camera memory. Values come from the paper's update rule. Drag along the step track or press play.

A product with missing features

Amazon Photo is a co-purchase graph. Each node is a product, an edge joins two products bought together, and the task is to predict each product's category.

A graph neural network predicts a node's label by mixing its features with its neighbours' features. Most of them lose a lot of accuracy when features go missing.

The paper tests this case directly. It masks 50% of the node features on Amazon Photo and measures accuracy again (Table 2). Two standard graph networks, APPNP and GraphSAGE, fall from 92.2% to 65.0% and from 93.9% to 73.3%. GIN is the exception at 91.1%.

The worked example below is that situation at toy size. Product C lost its features, so its vector is all zeros. It is bought together with two cameras and one lens, and it has to lean one way.

Four products, two memories

Each product is a point in a 2-dimensional feature space. The first coordinate says how camera-like a product is, and the second how lens-like. These values are illustrative, chosen to be small enough to check by hand.

There are two memories: a camera memory at (2, 0) and a lens memory at (0, 2). Camera A sits at (1.8, 0.2) and camera B at (1.4, 0.6). Lens D sits at (0.4, 1.6), and product C at (0, 0).

Each step moves all four products at once. The settings are the paper's starting values: four steps, β = 1, α = 0.3 and λ = 0.3 (Table 4). The paper learns β, and uses λ = 0.3 only on homophilous graphs. The next three sections explain each symbol.

Four steps move C toward the cameras

Illustrative example

position of product C
C's camera weight

Computed with the paper's update rule; the products and memories are illustrative. Step through with the arrows and watch C's trail.

After four steps, C sits at (1.15, 0.85) with a camera weight of 0.65. The camera weight is C's resemblance to the camera memory as a share between 0 and 1; the next section shows how it is computed.

The memory pull

Each step compares a node with every memory using a dot product. A softmax turns those scores into weights that sum to 1, and the node is pulled toward the weighted blend of memories.

A node is pulled toward the memories it resembles

Illustrative
camera · lens weights
blend the node is pulled to

The two memories of the worked example. Drag the node and notice the blend move toward the memory it resembles more; sharpness β is in the settings.

This blend is called retrieval, and the memories are stored patterns. With the stored patterns as the rows of a matrix M, retrieval for a node x is Mᵀ softmax(β M x) (Eq. 2).

At C's starting point (0, 0), both dot products are 0. The weights are 0.50 and 0.50, and the blend is (1.00, 1.00), exactly between the memories. Memory alone cannot tell C which way to lean.

β is the inverse temperature. A larger β sharpens the softmax, so a node is pulled toward its closest stored pattern almost alone. The paper starts β at 1.0 and learns it (Table 4).

The neighbour pull

The second pull comes from the graph. Each neighbour pulls C toward itself, scaled down by the degrees of both nodes.

Neighbours pull C toward themselves

Illustrative
Total on C:

Each neighbour's share and the total pull on C before the first step. Drag λ below zero and notice the total turn into a push.

This is the graph term. For a node v it adds −2λ (L X)v, where X holds every node's vector as a row. L = I − D−½ A D−½ is the normalized Laplacian, built from the adjacency matrix A and the degrees D (Section 2.1).

Written out, each neighbour u adds 2λ xu / √(du dv), and the node's own vector adds −2λ xv. C starts at zero, so only the neighbours count at first.

At λ = 0.3 the total pull on C is (0.92, 0.75), toward the cameras. Two of C's three neighbours are cameras, so the graph breaks the tie that memory left.

λ sets strength and sign. The paper uses λ = 0.3 on homophilous graphs, where linked nodes tend to share a label. It uses λ from −0.1 to 0 on heterophilous graphs, where they tend not to (Appendix A). A negative λ pushes neighbours apart; the paper calls this graph sharpening.

One update

An update adds both pulls, then mixes the result with where the node already was. This is the paper's rule (Eq. 2):

x_v ← (1 − α) x_v + α [ Mᵀ softmax(β M x_v) − 2λ (L X)_v ]

Keep a share of the old vector, and add the same share of the memory blend and the neighbour pull.

With α = 0.3, a node keeps 70% of its old vector and takes 30% of the two pulls. Every node updates at once from its neighbours' previous positions.

One step adds both pulls to C

Illustrative, rounded

C's move from step 1 to step 2 as a sum; every panel draws its vector from the origin on the same scale. Values are rounded to 2 decimals, so the pieces can miss the total by 0.01.

α is called damping: it keeps each move a fraction of the full pull, so nodes approach their targets over several steps instead of jumping.

C starts at zero, so its first step is short: 0.3 × [(1.00, 1.00) + (0.92, 0.75)] = (0.58, 0.53).

What each step lowers

Both pulls are slopes of one number. Eq. 1 adds a memory part for every node and one graph part for the whole graph:

E(X) = Σ_v [ −lse(β, M x_v) + ½‖x_v‖² ] + λ tr(Xᵀ L X)

The memory part is lowest when a node sits near a stored pattern, and the graph part is lowest when neighbours agree.

Here lse is log-sum-exp, a smooth maximum of β times the dot products, divided by β. The ½‖xv‖² part keeps vectors from growing without bound. The trace tr(Xᵀ L X) is a weighted sum of squared differences across edges (Prop. D.1).

The update in Eq. 2 is gradient descent on this total, with step size α (Prop. D.2).

Each step lowers the total

Illustrative example

The total and its two parts for the worked example at each step. Hover a step to read its values.

This total is the energy. In the example it falls from −4.74 to −7.03 over four steps. The graph part drops from 1.70 to 0.40 as neighbours move closer, and the memory part drops from −6.44 to −7.43.

Descent is guaranteed when the step size is below 2 / Llip. Llip bounds how fast the slope of the energy can change: Llip = β‖M‖² / 2 + 1 + 2λ‖L‖ (Corollary D.7). Here ‖L‖ is at most 2 (Corollary D.7), so Llip is at most 4.2. The step α = 0.3 is below 2 / 4.2 = 0.48. This guarantee needs no single minimum: each step lowers the energy even when there are several low points.

The memory part is what makes this a Hopfield network. Modern Hopfield networks recall a stored pattern by descending this log-sum-exp energy (Ramsauer et al., 2021). The GHN adds the graph part, so recall and smoothing happen in the same steps.

The general form

A layer runs T steps of Eq. 2 over all nodes at once. In matrix form, with one row per node, it fits in a few lines of NumPy:

import numpy as np

def softmax(z):
    e = np.exp(z - z.max(axis=-1, keepdims=True))
    return e / e.sum(axis=-1, keepdims=True)

def normalized_laplacian(A):
    s = 1 / np.sqrt(A.sum(axis=1))
    return np.eye(len(A)) - s[:, None] * A * s[None, :]

def ghn_step(X, M, L, beta=1.0, alpha=0.3, lam=0.3):
    R = softmax(beta * X @ M.T) @ M  # blend of stored patterns, one row per node
    G = -2 * lam * (L @ X)           # pull toward neighbours
    return (1 - alpha) * X + alpha * (R + G)

M = np.array([[2.0, 0.0], [0.0, 2.0]])                          # camera, lens
X = np.array([[1.8, 0.2], [1.4, 0.6], [0.0, 0.0], [0.4, 1.6]])  # A, B, C, D
A = np.zeros((4, 4))
for u, v in [(0, 1), (0, 2), (1, 2), (2, 3)]:
    A[u, v] = A[v, u] = 1
L = normalized_laplacian(A)
for t in range(4):
    X = ghn_step(X, M, L)
print(X[2].round(2), softmax(X[2] @ M.T).round(2))  # [1.15 0.85] [0.65 0.35]

The three lines of ghn_step are the memory blend, the neighbour pull and the damped mix. Run on the worked example, it prints C's position and weights after four steps.

The full model wraps this loop in four more pieces (Sections 2.2 and 2.3, Appendix A):

A gate
Before each update the blend rv is mixed with the node: r̃v = gv ⊙ rv + (1 − gv) ⊙ xv, with gv = σ(Wg[xv ‖ rv] + bg) (Eq. 3). The bias bg starts at 2, so the gate starts near 0.88 and leans on memory.
Three ways to retrieve
LSE is the softmax above. LSR replaces it with Epanechnikov weights, which give distant patterns zero weight. Hier(G) routes a node to one of G groups of patterns by their centroids, then retrieves inside that group. The paper uses G = 8.
A stack
An encoder maps features to vectors. Then two GHN layers each run T = 4 steps with gating, and a linear classifier predicts the label. Skip connections with weight 0.1, dropout and LayerNorm sit around the layers. The same M scores and blends, so keys and values are tied.
NoMem
The paper's main ablation removes the memory part and keeps the damped graph update. It shows how much of the result comes from the steps alone.

The paper's grid uses 64 or 256 stored patterns and a hidden size of 64 dimensions or 128 dimensions. It uses α = 0.3, T = 4 steps per layer and two layers, λ = 0.3 on homophilous graphs, and learns β from 1.0 (Table 4).

Results

The paper classifies nodes on nine graphs. Three are citation networks (Cora, CiteSeer, PubMed), two are Amazon co-purchase graphs (Photo, Computers), and four are heterophilous (Texas, Wisconsin, Cornell, Actor). Each model is tuned per dataset, and results are means over 10 seeds (Section 3.1).

94.7%NoMem on Amazon Photo, best in its columnTable 1
+5.0 pointsHier(8) over NoMem with 50% of features maskedTable 2
81.4%GHN-LSE on Texas, against 78.4% for GPR-GNN, a model built for heterophilyTable 3

The steps carry the Amazon results

Every GHN variant beats every baseline on both Amazon graphs, including NoMem (Table 1). NoMem is best on Photo at 94.7%, 0.8 points above GraphSAGE at 93.9%. On Computers it reaches 91.5%, 2.6 points above GIN at 88.9%.

GCN, APPNP and MLP are bimodal on Computers. Some seeds reach about 87% and others collapse to about 50%, across the whole tuning grid (Appendix A).

The paper concludes that the iterative update itself does much of the work. Photo has 238k edges against Cora's 10.6k, so smoothing alone has plenty of signal there (Section 3.2).

Where memory adds accuracy

On citation graphs, memory beats NoMem by 2.0 points on Cora with Hier(8). LSR adds 1.1 points on CiteSeer and 0.9 points on PubMed. Only on Cora do the two ranges of one standard deviation not overlap; on CiteSeer and PubMed they overlap (Section 3.2). GAT or APPNP still score highest on all three (Table 1).

Memory pays off when features are masked

Table 2 · paper
Hier(8) minus NoMem:

Mean accuracy over 10 seeds on Amazon Photo with 50% corruption; the hollow dot is clean data. Switch the corruption type and compare Hier(8) with NoMem.

With half of Photo's features masked, Hier(8), the best memory variant, keeps 91.9% and NoMem 86.9%, a 5.0 point gap. LSR keeps 91.0% and LSE 89.4%. Under edge drop and feature noise, NoMem matches the memory variants (Table 2), so memory does not protect against every kind of damage.

The gate does not explain the gain. In a separate GHN-LSE run on Photo, accuracy falls from 93.6% to 67.9% as masking rises from 0% to 70%. The gate's mean value moves only from 0.727 to 0.723 (Table 10). The paper credits the stored patterns, which carry class-level information that the masked features lack (Appendix C.6).

Product C is the extreme case: it lost every feature, so its memory scores tied. The paper masks half the features, which leaves each node something to compare.

Heterophilous graphs need λ at or below zero

On Texas, Wisconsin, Cornell and Actor, linked pages often have different labels. Pulling them together hurts: on Wisconsin, GCN scores 55.7% against 82.2% for an MLP, which ignores the edges (Table 3).

More smoothing helps citation graphs and hurts the rest

Table 6 · paper
Marker at

GHN-LSE accuracy at eight values of λ with one default configuration, not per-model tuning. Drag the marker to read every dataset at one λ.

With λ tuned at or below zero, GHN-LSE reaches 81.4% on Texas against 78.4% for GPR-GNN, a model built for heterophily. GPR-GNN leads on Wisconsin, 82.9% to 82.5% (LSR), and on Cornell, 80.3% to 78.9%. These gaps all sit within overlapping standard deviations (Section 3.4).

In the single-configuration sweep, a small negative λ beats λ = 0. Texas rises from 74.1% to 78.6% at λ = −0.05, and Wisconsin from 79.8% to 81.8% (Tables 6 and 7). λ = −0.3 does worse than −0.05 on all four datasets.

Full versions of Tables 1, 2 and 3 are in the reference section.

Limits

A lower energy does not guarantee a better classification. More steps keep lowering the energy, and they keep pulling neighbours together.

Extra steps pull the lens into the cameras

Illustrative example

Camera weight of each product over 30 steps of the worked example. Drag the marker to stop at any step; λ = 0 is in the settings.

In the example, lens D has a camera weight of 0.13 at step 4. It passes 0.50 at step 16 and reaches 0.96 at step 30, while the energy keeps falling to −7.96. When neighbours are pulled this close, their classes blur; this is over-smoothing.

The paper sees the same pattern. Cora peaks at 81.8% with T = 4 steps and drops to 30.9% at T = 16 steps. Texas and Wisconsin are best at T = 1 (Table 8).

Check yourself

You rerun the worked example with λ = 0. Where is product C after four steps?

Your graph is dense and its features are clean, like Amazon Photo. What should adding memory to the steps do?

You move to Wisconsin, where linked pages usually have different labels. Which change does the paper make?

Every step lowers the energy. Why does the paper stop at T = 4 on Cora instead of running 16 steps?

What to keep

Product C lost its features, so memory alone left it at 0.50. Its neighbours broke the tie, and four steps moved it to a camera weight of 0.65. The same steps, run too long, would pull lens D into the cameras.

The principle: the repeated downhill steps do most of the work. What they descend toward matters most when the graph or the features are weak. The paper's phrase is that iterative energy descent matters more than what you descend on (Section 4).

For the derivations, read Section 2 and Appendix D of the paper. For the memory side on its own, read Hopfield Networks Is All You Need (Ramsauer et al., 2021).

Reference

Glossary

Camera weight
In the worked example, a product's softmax weight on the camera memory, between 0 and 1.
Stored pattern
One memory vector, a row of M. The paper learns 64 or 256 of them per layer.
Retrieval
The softmax-weighted blend of stored patterns, Mᵀ softmax(β M x).
Inverse temperature (β)
Sharpness of the softmax. Larger values pull a node toward its closest stored pattern alone.
Graph term
The pull −2λ (L X)v toward a node's neighbours, from the Laplacian part of the energy.
Graph weight (λ)
Strength and sign of the graph term. Positive smooths; negative sharpens.
Damping (α)
The share of the pulls a node takes per step; it keeps 1 − α of its old vector.
Energy
The total in Eq. 1. Each update is a gradient step that lowers it.
Gate
A learned per-feature mix of the blend and the node before each update (Eq. 3).
LSE, LSR, Hier(G)
Softmax retrieval, Epanechnikov retrieval, and grouped retrieval over G groups.
NoMem
The ablation with no memory part: damped graph updates only.
Over-smoothing
Neighbours pulled so close that their classes blur.
Homophilous, heterophilous
Graphs where linked nodes tend to share a label, or tend not to.
Baselines
GCN, GAT, GraphSAGE, APPNP and GIN are standard graph neural networks that mix neighbour features. MLP uses each node's own features only. GPR-GNN is built for heterophilous graphs (Section 3.1).
Checked against the source
  • Paper: Rao, Wa and Athavale, arXiv 2603.03464v1, 3 March 2026, ICLR 2026 workshop. Equations: Eq. 1 (energy), Eq. 2 (update), Eq. 3 (gate); Prop. D.1, Prop. D.2, Corollary D.7; Sections 2.1, 2.2, 2.3, 3.1, 3.2, 3.3, 3.4, 4; Appendix A, Appendix C.6, Appendix D; Figure 4.
  • Illustrative, computed by this guide's code (check-example.mjs prints them): memories (2, 0) and (0, 2); A (1.8, 0.2), B (1.4, 0.6), C (0, 0), D (0.4, 1.6); a 2-dimensional space and 2 dimensions; four products; C's weights 0.50 and 0.50 and blend (1.00, 1.00) at step 0; pull on C (0.92, 0.75) at λ = 0.3; first step 0.3 × [(1.00, 1.00) + (0.92, 0.75)] = (0.58, 0.53); 70% kept and 30% taken at α = 0.3; after four steps C at (1.15, 0.85) with camera weight 0.65 (0.65 and 0.35 in the code); energy −4.74 to −7.03, graph part 1.70 to 0.40, memory part −6.44 to −7.43; L_lip at most 4.2 and 2 / L_lip = 0.48 with ‖L‖ at most 2; with λ = 0, C at (0.76, 0.76) and 0.50; lens D at 0.13 after step 4, past 0.50 at step 16, 0.96 at step 30, energy −7.96; the limits figure runs 30 steps; the example runs 4 steps; β‖M‖² = 4; weights sum to 1; values rounded to 2 decimals, off by up to 0.01.
  • Paper settings (Table 4, Appendix A): β = 1 (starts at 1.0, learned), α = 0.3, λ = 0.3, T = 4 steps, two layers, G = 8, gate bias 2 (gate near 0.88, Section 2.2), skip weight 0.1, 64 or 256 stored patterns (64 stored patterns or 256), hidden size 64 dimensions or 128 dimensions; heterophilous λ from −0.1 to 0. Results are means over 10 seeds on nine graphs.
  • Table 1: NoMem 94.7% on Photo, LSE 94.5%; GraphSAGE 93.9%, a 0.8 point gap; Computers NoMem 91.5% vs GIN 88.9%, a 2.6 point gap; memory variants within 0.5 points of NoMem on Amazon (Section 3.2); Cora +2.0 points, CiteSeer +1.1 points, PubMed +0.9 points over NoMem (Section 3.2). Bimodal seeds near 87% and 50% (Appendix A). Photo 238k edges, Cora 10.6k.
  • Table 2, 50% corruption on Photo: clean APPNP 92.2% and GraphSAGE 93.9%; feature mask APPNP 65.0%, GraphSAGE 73.3%, Hier(8) 91.9%, NoMem 86.9%, a 5.0 point gap, LSR 91.0%, LSE 89.4%, GIN 91.1%.
  • Table 3: GHN-LSE 81.4% on Texas vs GPR-GNN 78.4%; Wisconsin GPR-GNN 82.9% vs LSR 82.5%; Cornell 80.3% vs 78.9%; Wisconsin GCN 55.7% vs MLP 82.2%.
  • Table 6: Wisconsin 79.8% at λ = 0, 55.1% at λ = 0.3, 44.9% at λ = 1.0; eight values of λ. Table 6 and Table 7: λ = 0 gives 74.1% on Texas and 79.8% on Wisconsin; λ = −0.05 gives 78.6% on Texas and 81.8% on Wisconsin; λ = −0.3 lower than −0.05 on all four datasets.
  • Table 8: Cora 81.8% at T = 4 steps and 30.9% at T = 16 steps; Texas and Wisconsin best at T = 1. Table 10: gate 0.727 to 0.723, accuracy 93.6% to 67.9% from 0% to 70% masking. Table 11: β‖M‖² above 2 on 7 of 9 datasets, 35.96 on Photo. Figure 4: flat LSE needs 256 stored patterns on Photo; LSR stable with 64. Section 4: 1.5 to 2 times GAT's time per epoch.
  • Ramsauer et al., 2021, cited by the paper for modern Hopfield retrieval.

Table 1: accuracy on clean graphs

Node classification accuracy (%), mean ± std over 10 seeds, per-model tuning. † marks bimodal results (std above 10). Source: Table 1, p. 3.

ModelCoraCiteSeerPubMedPhotoComputers
LSE82.0 ± 0.670.9 ± 0.877.9 ± 0.494.5 ± 0.391.3 ± 0.2
LSR82.0 ± 0.670.9 ± 1.078.1 ± 0.494.4 ± 0.291.3 ± 0.4
Hier(8)82.3 ± 0.470.3 ± 1.177.6 ± 0.894.2 ± 0.291.3 ± 0.2
NoMem80.3 ± 0.469.8 ± 1.177.2 ± 0.694.7 ± 0.291.5 ± 0.2
GCN82.2 ± 0.472.2 ± 0.579.4 ± 0.489.6 ± 0.373.7 ± 13.0 †
GAT82.8 ± 0.872.3 ± 0.678.2 ± 0.492.2 ± 0.387.9 ± 0.6
GraphSAGE80.2 ± 0.670.5 ± 0.877.9 ± 0.493.9 ± 0.287.4 ± 0.4
APPNP82.8 ± 0.772.4 ± 0.580.3 ± 0.292.2 ± 0.341.9 ± 13.1 †
GIN77.5 ± 1.263.8 ± 2.377.6 ± 0.793.0 ± 0.588.9 ± 0.5
MLP60.0 ± 0.860.6 ± 0.673.4 ± 0.588.5 ± 0.375.4 ± 11.9 †

Table 2: accuracy under 50% corruption on Amazon Photo

Accuracy (%), mean ± std over 10 seeds, from a separate sweep tuned for robustness, so clean values can differ from Table 1. Source: Table 2, p. 4.

ModelCleanEdge dropFeature maskFeature noise
LSE94.4 ± 0.393.7 ± 0.489.4 ± 1.893.9 ± 0.3
LSR94.3 ± 0.293.7 ± 0.591.0 ± 2.494.1 ± 0.2
Hier(8)94.2 ± 0.293.7 ± 0.591.9 ± 1.193.9 ± 0.1
NoMem94.4 ± 0.394.0 ± 0.586.9 ± 3.194.2 ± 0.3
GCN89.7 ± 0.389.1 ± 0.581.2 ± 1.589.7 ± 0.3
GAT92.2 ± 0.391.2 ± 0.581.4 ± 5.092.2 ± 0.2
GraphSAGE93.9 ± 0.293.0 ± 0.373.3 ± 1.893.6 ± 0.3
APPNP92.2 ± 0.391.7 ± 0.365.0 ± 1.891.8 ± 0.3
GIN92.6 ± 0.489.6 ± 0.891.1 ± 0.992.6 ± 0.5
MLP88.5 ± 0.388.5 ± 0.370.7 ± 0.686.6 ± 0.2

Table 3: accuracy on heterophilous graphs

Accuracy (%), mean ± std. GPR-GNN values are published results on the same splits, not rerun; Actor was not reported. Source: Table 3, p. 5.

ModelTexasWisconsinCornellActor
LSE81.4 ± 1.582.2 ± 0.678.1 ± 3.238.0 ± 0.5
LSR80.8 ± 1.582.5 ± 1.178.9 ± 1.737.9 ± 0.5
Hier(8)80.5 ± 3.382.2 ± 1.778.1 ± 2.037.8 ± 0.6
NoMem80.5 ± 1.782.4 ± 0.978.6 ± 2.438.0 ± 0.7
GPR-GNN78.4 ± 4.482.9 ± 4.280.3 ± 8.1not reported
MLP80.3 ± 1.882.2 ± 0.673.0 ± 0.037.6 ± 0.4
GraphSAGE78.4 ± 1.880.0 ± 0.876.2 ± 1.737.0 ± 0.5
GCN70.3 ± 1.355.7 ± 1.040.3 ± 0.928.8 ± 0.4
GAT68.6 ± 2.358.0 ± 1.943.8 ± 4.029.4 ± 0.6
APPNP70.0 ± 1.556.7 ± 1.143.2 ± 3.632.4 ± 0.6
GIN64.9 ± 0.050.4 ± 1.655.7 ± 6.327.3 ± 0.5

Sources

This guide was written with AI and checked against the paper above. The worked example, its values and every figure marked illustrative are the guide's own construction, computed by its code, not results from the paper. Report corrections at github.com/juanbermudez/skills/issues.