Learn with objects and relationships.
Train shared graph messages, change directed relationships and test whether reordering objects changes their predictions.
By the end: Distinguish graph structure, programmed propagation and learned messages; trace two rounds and explain permutation equivariance and local information limits.
Start with something concrete.
Objects A, B, C and D form a directed chain. Only A is flagged. Can two rounds of messages tell C about A—and should they tell D?
Try the interactive model ↓On A → B → C → D, only A is flagged. Which objects can receive that flag within at most two arrows, including A itself?
Change one thing. Watch what follows.
- Inspect object C before training. Follow its incoming mean, first state, second state and prediction. Compare the exact target and fixed max rule.
- Train four requests of 250 updates at rate 0.3. Compare the graph model with the node-only baseline on training and repeated development.
- Remove B → C. Predict which targets change, then inspect C and D. Restore the arrow and toggle a flag. Edited graphs never enter training.
- Reverse node storage order. Check that the same named objects keep the same predictions even though their positions move.
- Try the branch, disconnected and six-object wide-neighborhood graphs. Capture up to three probes and export an explanation of failures, receptive-field limits and evaluation limits.
Loading this browser experiment…
Objects alone do not describe a scene
A cup, a table and a robot are three objects. “The cup is on the table” and “the robot can reach the cup” add relationships. A graph represents objects as nodes and relationships as edges. The shared-representation lesson includes typed relationships and a programmed propagation example. Storing a graph or running a fixed rule over it does not make it a learned graph neural network.
Here we fit shared neural transformations to a small task. Each object has a binary flag, 0 or 1. A directed arrow A → B means information can travel from A to B. The target for an object is 1 if a flagged object can reach it in zero, one or two arrows. Zero includes the object’s own flag. This is a synthetic relation exercise, not a physical hazard model.
If you enter midway: a feature is an input value such as the flag; a parameter is an adjustable weight or bias; and training adjusts parameters using examples with known targets. The graph’s coordinates on the screen are only a drawing. Neither names nor drawing positions are model inputs.
Follow a flag through a chain
Start with A → B → C → D and flag A. An exact two-step rule should mark A, B and C, leaving D unmarked. In round one, B receives A’s value while C receives B’s preceding value. Round two lets A’s information reach C through B. All nodes update simultaneously within each round. Updating nodes one by one in place could accidentally carry information across the whole chain in one pass.
The workbench offers three different mechanisms:
- A programmed max rule takes the maximum of each node’s own value and its incoming neighbors’ values, twice. It exactly expresses this task; there is no reason to expect a learned model to beat it here.
- A node-only baseline learns a logistic prediction from just the node’s own flag. Two nodes with the same flag always receive the same probability, even if their neighborhoods differ.
- A learned message-passing model averages incoming states, combines that message with the node’s own state, and learns the weights used at every node.
The exact targets come from a separate directed breadth-first search capped at two edges. That search and the displayed max rule are programmed algorithms; their agreement checks the task definition independently of neural predictions.
Read one learned layer as arithmetic
For each node, gather the values on arrows pointing into it. Average them. With incoming values 1 and 0, the message is (1 + 0) / 2 = 0.5. With no incoming arrows, we explicitly define the message as 0; the node’s own state still has a separate term.
Suppose the node’s own flag is 0. At initial weights, the first-layer score is 0.4 × 0 + 0.5 × 0.5 − 0.1 = 0.15. Applying tanh gives approximately 0.1489. This state is a learned numerical representation, not yet a probability or an exact logical flag.
i identifies the receiving node; j → i means an incoming edge from j. r is the layer number, 1 or 2. hᵢ⁽⁰⁾ is the observed flag; later h values are states between −1 and +1. m is the incoming mean. aᵣ weights the own-state contribution, bᵣ weights the incoming message and cᵣ is a bias. All are dimensionless. Read the update as “combine my previous state with the average of my neighbors’ previous states, then apply tanh.”
The same three layer parameters apply to every node, regardless of its name. Layer two has its own three parameters and consumes the first layer’s states. A final weight and bias convert the second state to a score, then sigmoid converts the score to a probability. This gives eight graph-model parameters. The node-only baseline has two separate parameters and its own loss.
Practice: if both incoming values become zero, the initial first-layer score is −0.1 and the state is approximately −0.0997. A negative hidden value does not mean a negative probability. Trace the later head before making that interpretation.
Learning changes shared transformations
Train with rate 0.3 for 1,000 updates. The actual mean binary cross-entropy gradients update all parameters simultaneously. The training set contains 48 four-node graphs, or 192 node targets. The repeatedly visible development set contains 36 five-node graphs, or 180 node targets. Development graphs change size and topology but follow the same narrow generating rules and target definition.
The edited graph is an inspection probe. Adding an edge, toggling a flag or reversing storage order does not train on that graph or alter the training set. Capture it to document an intervention rather than treating every new click as independent evidence.
The learned model can use neighborhood information unavailable to the node-only baseline. That comparison also changes parameter count and computation. Equal update budgets are not equal total work. The fixed exact rule is a deliberately strong task-specific reference, not a neural model or a baseline that must be outperformed for the exercise to be useful.
Optional implementation: differentiate through both rounds
For one node’s final score, the binary cross-entropy derivative is probability − target. Divide by the total number of nodes in the batch. Backpropagate through the output head and the second tanh, whose derivative is 1 − state².
A second-layer error contributes to its own node’s first state through the own-state weight. It also contributes to every incoming neighbor’s first state through the message weight divided by the receiving node’s incoming degree. Accumulate all these contributions before differentiating the first layer. Update both layers only after all gradients have been computed from the preceding parameters. The tests compare every derivative with central finite differences.
Move the drawing without changing the graph
Click Reverse node storage order. A valid permutation reorders node features and remaps every edge endpoint. The same named object may move on screen, but its corresponding prediction should remain the same up to numerical rounding. The workbench calculates the largest corresponding probability difference.
This is permutation equivariance: node outputs follow the node reordering. It differs from graph-level invariance, where one summary for the whole graph remains unchanged. We do not train a whole-graph output in this lab.
Reordering features without remapping edges describes a different graph. Adding an edge, reversing an arrow or toggling a flag is also a real intervention, not a permutation. Predictions may appropriately change. Try removing B → C in the chain and explain which exact targets change before inspecting the neural result.
Know what local messages cannot prove
Two rounds cannot see a flagged source three directed edges away. This is a structural limit of this architecture, not something extra training can repair. Our target deliberately requires at most two edges. Changing the target to “reachable at any distance” would require another algorithm or architecture, not merely relabeling this successful result.
Try the six-object wide incoming neighborhood after the guided 1,000-update run. Object A receives one flagged neighbor among five: the mean is 0.2. The exact target remains 1, but this trained model predicts below 50%. Training had at most three incoming neighbors and the fixed development set at most four. This higher-degree probe exposes a failure despite perfect development accuracy. The received signal is diluted by averaging; a new degree distribution deserves its own evaluation.
Averaging also loses information. One flagged neighbor out of two and two flagged neighbors out of four have the same mean. A model that receives only that mean and the same own state cannot infer the exact neighbor count from that layer. Other aggregations, degree features or richer representations can address some tasks, but each introduces its own assumptions.
The toy graph uses one relation type. The earlier “on” and “can-reach” labels express different meanings; this model does not learn relation-specific weights, extract objects from an image or infer missing edges. A reliable system must also account for uncertain detections, incorrect relationships and different real-world data. Perfect performance on the small supplied development set does not establish those capabilities.
Make a graph argument from evidence
For guided practice, export a trace explaining how a flag reaches C but not D. Compare a changed edge with a pure permutation. For implementation practice, reproduce the incoming mean, simultaneous forward passes and shared gradients; add a test that catches feature-only reordering without endpoint remapping. For a decision brief, explain why the exact programmed rule is preferable when it already solves a known contract, and what evidence would justify learning a less explicit relationship.
These are practice artifacts. Independent learner assessment and human review of implementation or reasoning remain separate work. The message-passing research paper gives a broader framework and molecular applications; this tiny flag predictor does not reproduce its chemistry models or results.
After changing the node order, you permute the flag array but forget to remap the edge endpoints. Predictions change. What does this show?
Take this idea with you.
A graph tells you what is connected. A programmed rule specifies what to propagate. A learned model fits shared transformations—but only from the information its messages can reach.