~/writing
Graph ML

Introduction to Graph Neural Networks

An overview of graph representations, adjacency matrix limitations, message passing mechanisms, and key design choices in GNN architectures.

Uses of Graphs in Everyday Life

Graphs are all around us and can be used to map out relationships and connections between entities. Some common examples include friendships, social networks, or train stations. A graph represents the relations between entities and consists of vertices (nodes) and edges (links between nodes).

Challenges in Using Graphs in Machine Learning

Graphs have 4 types of information that we can potentially use to make predictions: nodes, edges, global context, and connectivity.

The first three are easier to represent — for example, nodes can be represented using a matrix $N$ and assigning an index to each node before storing them inside the matrix.

Although you can use an adjacency matrix to represent connectivity, it becomes complicated once the number of nodes reaches millions. The edges (connections) become highly variable, which results in very sparse matrices that are space-inefficient. Another issue is that while adjacency matrices can encode connectivity, they are not permutation invariant, as one graph can have different matrix representations.

Two adjacency matrices representing the same graph.

One elegant way of representing sparse matrices is through adjacency lists. Since the number of edges is typically much lower than the total possible connections, adjacency lists avoid computation and storage overhead on disconnected parts of the graph.

Passing Messages Between Parts of the Graph

To make learned embeddings aware of graph connectivity, we use message passing, where neighboring nodes or edges exchange information to update each other’s representations. This process happens in 3 steps:

  1. Gather: Collect neighboring node embeddings/messages for each node.
  2. Aggregate: Combine messages using an aggregation function (e.g., SUM, MEAN, MAX).
  3. Update: Pass pooled messages through an update function to compute the new node embeddings.

This is analogous to convolutions in computer vision: both operations aggregate neighboring information to update a target element (a node in graphs, or a pixel in images). However, graph nodes have a variable number of neighbors, unlike pixels which have a fixed local grid.

By stacking message-passing GNN layers, nodes incorporate information from farther across the network:

  • A 1-layer GNN aggregates 1-hop neighbors.
  • A 3-layer GNN incorporates information up to 3 steps away.

Overcoming Propagation Limits with Master Nodes

If $K$ layers are applied, information only propagates at most $K$ steps away. Nodes far apart cannot easily communicate if prediction tasks depend on global structure.

To avoid the computational expense of all-to-all connectivity, a global graph representation (or master node) can be introduced. The master node connects to every node in the graph, serving as a high-speed communication bridge to build a holistic graph-level representation.

Key Components in a GNN Design Space

Customizing a GNN architecture involves tuning several key hyperparameters:

  • Depth: Number of GNN layers.
  • Width: Dimensionality of hidden feature attributes per layer.
  • Aggregation Function: Pooling operator (SUM, MEAN, MAX).

Architectural Observations & Bottlenecks

  • Parameter Efficiency: GNNs achieve strong performance even with low parameter counts, though performance generally scales with parameter budget.
  • Layer Depth vs. Dilution: Performance often peaks around 2 layers. Beyond 3–4 layers, node representations risk becoming diluted due to over-broad broadcasting across distant nodes.
  • High-Dimensional Distance Collapse: In excessively high dimensions, distance metrics (e.g., Euclidean distance, Cosine similarity) lose discriminative capability as vectors become equidistant.
  • Over-squashing: As depth increases, the number of receptive nodes grows exponentially. Cramming thousands of neighborhood signals into a fixed-size node vector causes critical messages to be compressed, distorted, or lost to local noise.

Mitigation Strategies

To handle high feature dimensions and deep architectures:

  • Use Principal Component Analysis (PCA) or linear projections to reduce initial node feature dimensions prior to training.
  • Apply Layer Normalization to stabilize feature magnitudes across message-passing iterations.