liveBook · Manning

Graph neural network

As explained in Graph Neural Networks in Action

A graph neural network architecture specifies the layers, computations, and connectivity used by a graph neural network.

A graph neural network (GNN) learns from entities and their relationships. Its architecture specifies how graph features move through neural-network layers and how connected nodes exchange information. Use one when relationships matter to the prediction: for example, when users interact with items, atoms form molecules, or effects propagate through a network. If observations are standalone and their relationships add little information, a GNN may not be a good fit. section 1.2.4 section 1.6

A practical GNN model follows this path:

  • Represent the data as nodes, edges, and features. Decide what each represents before choosing layers. section 1.5.1
  • Apply a message-passing layer. Each node receives information from its neighborhood; an aggregation combines those messages with its own features to update its embedding. section 2.2.1 section 1.6
  • Stack layers and ordinary neural-network operations as needed. A two-layer graph convolutional network (GCN), for instance, places an activation and dropout between its convolution layers. section 2.2.1
  • Train the model for the intended output, such as a node, edge, or whole-graph prediction. The embeddings are refined during training rather than necessarily generated in a separate preprocessing step. section 1.6 section 2.0
Listing 2.4 Our SimpleGNN class
class SimpleGNN_embeddings(torch.nn.Module):
    def __init__(self, num_features, hidden_channels):   #1
        super(SimpleGNN, self).__init__()
        self.conv1 = GCNConv(num_features, \
hidden_channels)   #2
        self.conv2 = GCNConv(hidden_channels,\
 hidden_channels)  #3

    def forward(self, x, edge_index):   #4
        x = self.conv1(x, edge_index)  #5
        x = torch.relu(x)   #6
        x = torch.dropout(x, p=0.5, train=self.training)   #7
        x = self.conv2(x, edge_index)    #8
        return x   #9

The two-layer PyTorch Geometric example shows the architecture in code: each GCNConv receives node features and edge_index; ReLU and dropout sit between the layers, and forward returns node embeddings. Passing an untrained graph through it illustrates the mechanism, not task-trained predictions. section 2.2.1

Choosing a graph and a prediction

For a recommender, represent users and items as nodes and interactions as edges; this exposes connections hidden in sparse interaction data. For a molecular-property prediction, atoms are nodes and bonds are edges, and the desired output concerns the whole graph. These choices determine what information the architecture must process and what it must predict. section 1.4.2 section 1.3.2

Architecture is only part of the workflow: graph construction, preprocessing, data splits, training, and inference also matter. Local message passing may struggle with distant dependencies; global attention, nonlocal aggregation, or hierarchical message passing are possible modifications. Very large graphs may also require changes to training, inference, and storage. section 1.5.1 section 1.4.3 section 1.3.1

How Graph Neural Networks in Action covers it

How deep it goes
Builds from graph representation to message-passing layers and a coded two-layer GCN; defers detailed convolution treatment.
Examples
Uses a two-layer GCN embedding model, sparse user-item interactions, and atom-bond graphs for molecular prediction.
What it assumes
Assumes familiarity with neural-network layers and training hyperparameters while introducing the graph fundamentals needed for GNNs.
What you can do after
Build it from scratch as a basic two-layer GCN in PyTorch Geometric and evaluate whether graph relationships justify its use.
How it connects
Connects message passing, graph embeddings, graph convolutional networks, permutation invariance, and node, edge, and graph prediction.

Also explained in

Compare how 5 books explain graph neural network →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.