liveBook · Manning

Depth

As explained in Graph Neural Networks in Action

The number of computational layers in a neural network, especially the number of graph-processing layers in a graph neural network.

Depth is the number of layers in a neural network. In a GNN, each layer is a message-passing step that lets every node aggregate information from one additional hop of neighbors, expanding its receptive field. section 3.3.2

Choose depth by balancing neighborhood coverage against representation quality and computational cost:

  • Too few layers restrict each node to a small neighborhood and may produce weak representations. section 3.3.2
  • More layers reach farther nodes but can cause over-smoothing, making node features too similar to distinguish. section 3.3.2
  • Two- or three-layer GNNs often balance neighborhood information with over-smoothing and complexity; very deep models can also overfit. section 3.3.2

Comparing shallow and deep models

Training curves compare GNNs with 2, 10, and 50 layers. The 2-layer model has the strongest overall profile; the 10-layer model improves training loss but shows higher validation loss, while the 50-layer model degrades on both measures. section 3.3.2

A practical GraphSAGE implementation exposes depth through a configurable number of convolution layers. A refined baseline keeps two layers, combines aggregation experiments with 50% dropout, and outperforms the default mean-aggregation model in reported tests. section 3.3.3

Listing 3.7 GraphSAGE class
class GraphSAGEWithCustomDropout(torch.nn.Module):
   def __init__(self, in_channels, \
hidden_channels, out_channels, num_layers, \
dropout_rate=0.5, aggr='mean'):  #1
       super(GraphSAGEWithCustomDropout, self).__init__()
       self.layers = torch.nn.ModuleList\
([SAGEConv(in_channels, hidden_channels, aggr=aggr)])
       for _ in range(1, num_layers-1):  #2
           self.layers.append(SAGEConv\
(hidden_channels, hidden_channels, aggr=aggr))
       self.layers.append(SAGEConv\
(hidden_channels, out_channels, aggr=aggr))
       self.dropout_rate = dropout_rate

   def forward(self, x, edge_index):
       for layer in self.layers[:-1]:
           x = F.relu(layer(x, edge_index))
           x = F.dropout(x, p=self.dropout_rate, training=self.training)
       x = self.layers[-1](x, edge_index)
       return F.log_softmax(x, dim=1)

Inspect the configurable GraphSAGE class and model definitions to see how layer depth is selected alongside dropout and aggregation. section 3.3.3

How Graph Neural Networks in Action covers it

How deep it goes
Defines layers as graph hops, compares 2, 10, and 50 layers, and explains under-reaching, over-smoothing, overfitting, and complexity.
Examples
Compares 2-, 10-, and 50-layer training curves and implements two-layer GraphSAGE models with configurable aggregation and dropout.
What it assumes
Assumes basic GNN, graph-neighborhood, and GraphSAGE knowledge while defining depth through message-passing hops.
What you can do after
Evaluate GNN depth by comparing training and validation behavior while configuring GraphSAGE layers for experiments.
How it connects
Connects depth to message passing, receptive fields, neighborhood aggregation, over-smoothing, overfitting, and computational complexity.

Also explained in

Compare how 4 books explain depth →

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.