Machine learning models · Phase 4 · Lesson 36

Graph neural networks

Understand message passing over nodes and edges and the limits of graph representations.

This is one focused step in the 60-lesson course. Use the retrieval check before moving on.

Lesson goal

Understand message passing over nodes and edges and the limits of graph representations.

The core idea

Each node updates its representation by collecting information from neighbours. Repeating the process lets information travel farther through the graph.

Mental model

Picture it this way. Each node updates its representation by collecting information from neighbours. Repeating the process lets information travel farther through the graph. The important question is what assumption this picture makes, and whether that assumption fits the data.

Mathematical core

A message-passing layer aggregates neighbour messages, combines them with the node state and applies a learned update. Pooling produces graph-level representations.

Worked example

A fraud graph links accounts, devices and transactions. A node representation can use local connection patterns without flattening the graph into an arbitrary table.

When to use it

It earns a place when

  • Use GNNs when relationships are part of the data and the graph structure is meaningful at prediction time.
  • You can evaluate it against a credible baseline.
  • Its output fits the decision and data constraints.

Do not make it the default when

  • Do not build a graph merely because a neural network is fashionable. Check whether edges are reliable, available at inference and free of target leakage.
  • A simpler model has not been tested.
  • The data or target definition is still unclear.

Failure modes

Watch for this. Oversmoothing can make distant node representations indistinguishable. Dynamic graphs, scale and inductive versus transductive assumptions matter.

When a result looks surprisingly good, inspect the split, target timing, error slices and data-generating process before celebrating.

Practice

Use this as a small experiment rather than a recipe to copy blindly. Change one thing, record the result and explain the change.

Do this. Implement one message-passing layer on a toy graph. Compare node predictions using only node features versus features plus neighbour aggregation.

Retrieval check

Answer from memory first. The buttons reveal feedback, but the durable step is explaining why.

1. What does message passing aggregate?

2. What is a graph-level prediction?

3. What is oversmoothing?

Transfer prompt. Describe one real problem where this model or idea would be a sensible candidate. Name the target, the main risk and the metric you would inspect.

Primary source

Dive into Deep Learning. Use the source for the deeper treatment after you can explain the lesson's core idea without looking.