Graph neural networks

Graph neural networks

How graph neural networks pass messages along the edges of a graph to learn from molecules, materials, networks and other connected data, for node, edge and whole-graph predictions.

What it is

A graph neural network (GNN) is a neural network that works directly on data structured as a graph: a set of nodes (entities) connected by edges (relationships). Many scientific data are naturally graphs: atoms joined by bonds in a molecule or crystal, proteins and their interactions, social and citation networks, road and power networks, knowledge graphs and meshes in physical simulation. Ordinary networks need fixed-size grid or vector inputs, whereas GNNs handle graphs of different sizes and shapes, and give the same result regardless of how nodes are numbered. The main framework, message passing, was formalized by Gilmer et al. (2017), building on the graph neural network model of Scarselli et al. (2009) and the graph convolutional network (GCN) of Kipf and Welling (2017).

It answers questions such as: What is the property (energy, solubility, toxicity) of this molecule or crystal? Which class does this node (a paper, a user, a protein) belong to? Will these two nodes be linked (link prediction, for recommendations or drug–target interactions)? How does a physical system defined on a mesh evolve? Which structure of atoms gives a target property?

Fundamentals

Graph data and message passing

A graph G = (V, E) is described by an adjacency matrix A (Aij = 1 if nodes i and j are connected) and by node features X (for an atom: element, charge, hybridization) and optionally edge features (bond type, distance). A GNN layer updates each node’s representation in two steps. Aggregate: collect the representations of its neighbors N(v) with a permutation-invariant function (sum, mean or max). Update: combine the aggregate with the node’s own state through a learned transformation: hv(l+1) = σ(Wself hv(l) + Wnbr AGG({hu(l) : u ∈ N(v)})). After L layers, each node’s vector reflects its L-hop neighborhood, just as a convolutional network’s receptive field grows with depth (see CNNs). Because aggregation ignores neighbor order, the model is permutation equivariant for node outputs and invariant for graph-level outputs.

Common GNN architectures

  • GCN: H(l+1) = σ(D̃−1/2 à D̃−1/2 H(l) W(l)), with à = A + I (self-loops) and D̃ its degree matrix, a normalized neighborhood average.
  • GraphSAGE: samples a fixed number of neighbors and learns aggregators, which scales to big graphs and works on unseen nodes.
  • GAT (graph attention network): learns attention weights so that neighbors count differently.
  • GIN (graph isomorphism network): sum aggregation with an MLP, as expressive as the 1-Weisfeiler–Lehman graph test allows.
  • Message-passing neural networks with edge-dependent messages, used in chemistry (for example MPNN, D-MPNN in Chemprop).

Tasks and readout

Node-level tasks (classify nodes) use the final node embeddings with a classifier. Edge-level tasks (link prediction) score pairs of node embeddings, for example by a dot product. Graph-level tasks (predict a molecular property) need a readout that pools all node embeddings into one vector (sum, mean, max, or attention-based and hierarchical pooling such as DiffPool), followed by a regression or classification head. Training can be supervised on labels, semi-supervised on a partially labeled graph (as in the original GCN, where unlabeled nodes still contribute through the graph structure), or self-supervised (contrastive learning, masked node prediction, graph autoencoders). Large graphs use mini-batch methods with neighbor sampling or subgraph sampling (Cluster-GCN, GraphSAINT), since the full graph may not fit in GPU memory.

GNNs for molecules, materials and physics

For 3D atomic systems, the geometry matters, and physical quantities must transform correctly under rotation and translation. Invariant and equivariant GNNs (SchNet, DimeNet, PaiNN, NequIP, MACE, Allegro) use distances, angles and tensor features so that predicted energies are invariant and forces equivariant, and they form the basis of machine-learned interatomic potentials (see machine-learned interatomic potentials). Crystal graph networks (CGCNN, MEGNet, M3GNet) predict formation energy and band gaps for crystals, and in drug discovery GNNs predict toxicity, binding and ADMET properties and generate molecules. In physical simulation, mesh-based GNNs (MeshGraphNets, graph network simulators) learn fluid, solid and particle dynamics and can accelerate simulations by orders of magnitude, while weather models such as GraphCast use graphs on the sphere.

Challenges, typical applications and limits

Known issues: over-smoothing (representations of all nodes converge as layers increase, so GNNs are usually shallow, 2–6 layers), over-squashing (information from many distant nodes compressed into one vector), limited expressiveness (standard message passing cannot distinguish some non-isomorphic graphs), sensitivity to graph construction (cutoff radius, bond definitions), and the need for splits that reflect real use: random splits of similar molecules overestimate performance, so scaffold or cluster splits are preferred. Applications: property prediction, recommender systems, traffic forecasting, fraud detection, knowledge graph completion and protein interaction analysis. Libraries: PyTorch Geometric, DGL, Jraph (JAX) and Spektral.

Basic operation

  1. Define the graph. Decide what the nodes and edges are, and build features for each.
  2. Split the data. Use scaffold, cluster or time-based splits where leakage is likely.
  3. Choose an architecture. Use GCN or GAT for general graphs, equivariant models for 3D atoms.
  4. Set the readout. Add pooling for graph-level targets.
  5. Train. Optimize with Adam and monitor validation performance.
  6. Tune depth and size. Keep layers few to avoid over-smoothing.
  7. Evaluate. Test on a held-out set with proper metrics and baselines such as fingerprint models.
  8. Collect the output. You obtain node, edge or graph predictions; graph construction and message passing are covered in the video.

Good practice

  • Compare with simple baselines. Fingerprints and gradient boosting are strong for molecules.
  • Use realistic splits. Avoid near-duplicates across train and test sets.
  • Keep networks shallow. Add residual connections if you need depth.
  • Respect symmetry. Use equivariant models for 3D physical targets.
  • Report uncertainty. Use ensembles for property predictions.
  • Treat predictions as hypotheses. For toxicity or safety-related predictions on chemicals or drugs, confirm with experiments, and take care with privacy when graphs describe people.

Key terms

  • Message passing — nodes exchanging and aggregating information along edges.
  • Adjacency matrix — a matrix recording which nodes are connected.
  • Readout (pooling) — combining node embeddings into one graph-level vector.
  • Permutation invariance — a result that does not depend on node ordering.
  • Over-smoothing — node representations becoming indistinguishable in deep GNNs.
  • Equivariance — outputs that transform consistently when the input is rotated or moved.
  • Link prediction — predicting whether an edge exists between two nodes.

Video coming soon

About five minutes on Graph neural networks: how it works in detail, how the data is acquired, and how it is analyzed.

Shopping cart

0
image/svg+xml

No products in the cart.

Continue Shopping