Machine Learning

Message Passing Neural Networks

Message passing neural networks update node embeddings by sending transformed neighbor features into an aggregate-and-update step.

status: reviewimportance: criticaldifficulty 4/5math: graduateread: 22mlive demo

Concept Structure

Message Passing Neural Networks

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

2prerequisites
3next concepts
4related links

Learner Contract

What this page should let you do.

You are here becauseMessage passing neural networks update node embeddings by sending transformed neighbor features into an aggregate-and-update step.

This Machine Learning concept is the current idea: keep the same invariant visible across Intuition, Math, Code, Interactive Demo.

By the end4/4 sections ready | runnable code expected | live demo

Explain the mechanism, trace the main notation, and test one prediction in the live demo.

Do this firstIntuition

Read the intuition before the notation; the math should name a mechanism you already felt.

Test the linkManipulate one control and predict the visible change.Then continue to GCN, GraphSAGE, and GAT (review)

Claim/source review status

Substantive review recorded

1/1 claims have bounded review metadata; still check caveats and source scope.Metadata-derived; review may be AI-assisted. Not a human certification.
Claims1/1 reviewed
Sources4 cited
Codeattached
Demolive
Reviewed2026-07-02
Updatedpage 2026-07-02

Learning item flow

4/4 sections readyAsk about thisResearch room
ConceptMessage Passing Neural NetworksMachine Learning
4 sources attachedLocal snapshot ready
concept:machine-learning/message-passing-neural-networks
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

A graph neural network has to answer a simple question:

How can a node use the features of its neighbors without forgetting that the input is a graph, not a row in a table?

The usual answer is message passing.

Each node keeps a vector representation. During one layer, every node receives small messages from its neighbors, combines those messages in an order-independent way, and updates its own vector.

The phrase "message" is literal enough to be useful:

  • a neighbor has a current representation;
  • a learned function turns that representation into a message;
  • all incoming messages are aggregated;
  • the node combines the aggregate with its previous state.

The important constraint is that a graph has no natural ordering of neighbors. If node vv has neighbors a,b,ca,b,c, the result should not depend on whether the code happened to list them as a,b,ca,b,c or c,a,bc,a,b. This is why message-passing layers use aggregators such as sum, mean, max, or attention-weighted sums.

This is the first neural version of the adjacency idea. The adjacency matrix said where information can move. Message passing says what information moves, how it is pooled, and how it changes the node representation.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let G=(V,E)G=(V,E) be a finite graph. Each node vVv\in V has a hidden vector at layer \ell:

hv()Rd.h_v^{(\ell)}\in\mathbb{R}^{d}.

The one-hop neighborhood of vv is

N(v)={u:(u,v)E}.\mathcal{N}(v)=\{u:(u,v)\in E\}.

A message-passing layer can be written in three steps.

First, compute a message from each neighbor uu to node vv:

muv()=ϕm(hu(),hv(),euv).m_{u\to v}^{(\ell)} = \phi_m\left(h_u^{(\ell)}, h_v^{(\ell)}, e_{uv}\right).

Here ϕm\phi_m is a learned message function. The optional edge feature euve_{uv} can encode edge type, distance, bond type, or any edge annotation. This page keeps euve_{uv} out of the demo so the core mechanism stays visible.

Second, aggregate the incoming messages:

av()=AGGuN(v)muv().a_v^{(\ell)} = \operatorname{AGG}_{u\in\mathcal{N}(v)} m_{u\to v}^{(\ell)}.

The aggregator must be permutation-invariant. Mean aggregation is one simple choice:

av()=1N(v)uN(v)muv().a_v^{(\ell)} = \frac{1}{|\mathcal{N}(v)|} \sum_{u\in\mathcal{N}(v)} m_{u\to v}^{(\ell)}.

Third, update the node representation:

hv(+1)=ϕu(hv(),av()).h_v^{(\ell+1)} = \phi_u\left(h_v^{(\ell)}, a_v^{(\ell)}\right).

The update function ϕu\phi_u may be an MLP, a gated recurrent update, a residual block, or a simpler affine map plus nonlinearity.

The key invariant is local and repeated:

new node state=update(old node state,aggregate of neighbor messages).\text{new node state} = \text{update}\left( \text{old node state}, \text{aggregate of neighbor messages} \right).

After one layer, a node has information from one-hop neighbors. After two layers, it can contain information from nodes two hops away, because its neighbors have already absorbed their own neighbors.

This locality is powerful, but it also creates caveats:

  • many layers can blur node representations if aggregation repeatedly averages neighborhoods;
  • nodes with different local structure can still become hard to distinguish;
  • attention, normalization, residual connections, and edge features change the layer behavior;
  • implementation libraries use sparse batching and indexing tricks that are not visible in the small formula.

Those are later pages. This page isolates the mechanism every learner should feel first: send, aggregate, update.

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

edges = [(0,1), (0,2), (1,3), (2,3), (2,4), (3,4)]
h = np.array([
    [ 1.0, 0.1],
    [ 0.9, 0.2],
    [ 0.2, 0.8],
    [-0.4, 0.9],
    [-0.8, 0.7],
])

W_msg = np.array([[0.7, -0.2], [0.1, 0.8]])
W_self = 0.35 * np.eye(2)
b = np.array([0.05, -0.05])

neighbors = {i: [] for i in range(len(h))}
for i, j in edges:
    neighbors[i].append(j)
    neighbors[j].append(i)

next_h = np.zeros_like(h)
for v in range(len(h)):
    messages = np.array([W_msg @ h[u] for u in neighbors[v]])
    aggregate = messages.mean(axis=0)
    next_h[v] = np.maximum(0, W_self @ h[v] + aggregate + b)
    print(v + 1, "aggregate", aggregate.round(2),
          "updated", next_h[v].round(2))

The code mirrors the math: build neighbor lists, transform neighbor features into messages, average the incoming messages, then update each node.

04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

Predict which node representation changes the most after one mean-aggregation message-passing layer. Then reveal the incoming messages, aggregate vector, update vector, and delta for each candidate node.

Live Concept Demo

Explore Message Passing Neural Networks

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 4/5graduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Message Passing Neural Networks should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Message passing neural networks update node embeddings by sending transformed neighbor features into an aggregate-and-update step.

Prediction open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Message Passing Neural Networks should make visible.

Visual Inquiry

Make the image answer a mathematical question

Message passing neural networks update node embeddings by sending transformed neighbor features into an aggregate-and-update step.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Message Passing Neural Networks easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

paper · 2017Neural Message Passing for Quantum ChemistryGilmer, Schoenholz, Riley, Vinyals, and Dahl

Primary source for the message, aggregate, and update view used in the MPNN framework.

Open source
course-notes · 2026Stanford CS224W: Graph Neural NetworksStanford CS224W

Course source for node neighborhoods, aggregation, and graph neural network layer intuition.

Open source
article · 2021A Gentle Introduction to Graph Neural NetworksSanchez-Lengeling et al.

Pedagogical visual source for graphs with node features and neighborhood information flow.

Open source
documentation · 2026PyTorch Geometric: Creating Message Passing NetworksPyTorch Geometric

Open-source implementation reference for propagate, message, aggregate, and update hooks.

Open source

Claim Review

Message passing neural networks update node embeddings by sending transformed neighbor features into an aggregate-and-update step.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources4 references

gilmer-2017-mpnn, cs224w-gnn-message-passing, distill-2021-gnn-intro, pyg-messagepassing-2026

Local checks4 local checks

Use equations, runnable code, and demos to check whether the source support is operational.

Substantively reviewedA message-passing neural network layer updates each node by computing messages from neighboring node states, combining them with a permutation-invariant aggregation, and applying an update function to produce the next node representation.Claim metadata: source checked

The sources support the finite one-hop layer abstraction, neighbor messages, permutation-invariant aggregation, update functions, and the implementation mapping to message/aggregate/update hooks.

Sources: Neural Message Passing for Quantum Chemistry, Stanford CS224W: Graph Neural Networks, A Gentle Introduction to Graph Neural Networks, PyTorch Geometric: Creating Message Passing NetworksFinite one-layer mean-aggregation witness only; excludes training, sparse batching, edge-feature variants, directed graphs, over-smoothing, and GCN/GraphSAGE/GAT details.A bounded review summary is present; still check caveats and exact reference scope.

Checked Gilmer et al. for the MPNN message/update framework, CS224W for neighborhood aggregation and GNN layer intuition, Distill for graph-feature pedagogy, and PyTorch Geometric documentation for the practical message/aggregate/update API pattern. GPT Pro publication critique remains pending because 127.0.0.1:51672 is unavailable.

Reviewer: codex-local-source-review; reviewed 2026-07-02

Practice Loop

Try the idea before it explains itself

Message passing neural networks update node embeddings by sending transformed neighbor features into an aggregate-and-update step.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Message Passing Neural Networks.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Grounded research drawerClose
ConceptMessage Passing Neural NetworksMachine Learning

Research Room

Attach the question to a claim, equation, code, or demo

Pick the concept, equation, source, runnable code, claim, misconception, or demo state before asking for help. The handoff keeps that page item in context.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptMachine Learning

Message Passing Neural Networks

Attached question

What is the smallest example that makes Message Passing Neural Networks click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays in this browser, attached to the selected learning item.

No local draft saved.
Evidence to inspect
  • References to inspect: attached references on this page.
  • Definition, prerequisite, and contrast concept links
  • The equation or runnable code that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Message Passing Neural Networks Selected item key: recorded for copy. Context: Machine Learning Page anchor: recorded for copy. Open question: What is the smallest example that makes Message Passing Neural Networks click without losing the math? Evidence to inspect: - References to inspect: attached references on this page. - Definition, prerequisite, and contrast concept links - The equation or runnable code that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

View it in context
concept/concept-notebook/machine-learning/message-passing-neural-networks concept:machine-learning/message-passing-neural-networks