A graph convolutional network (GCN) learns from both node features and the edges between nodes. Use one when a prediction depends on a node’s neighborhood, not just its own attributes—for example, when predicting a product category from products that customers buy together. section 3.1 section 3.1.2
Think of graph convolution as local averaging over connected nodes. At each GCN layer, a node gathers information from its neighbors and combines it with its own features to update its representation, or embedding. Stacking layers lets information travel across more message-passing steps. GCN uses a normalized aggregation rather than a plain sum, which helps when node degrees vary widely. section 2.2.1 section 3.0 section 3.4.3
A practical PyTorch Geometric (PyG) pipeline is:
- Prepare node features and graph connections as `x` and `edge_index`; choose a manageable subgraph if the full graph strains available resources. section 3.1 section 3.1.2
- Stack two `GCNConv` layers with a ReLU activation between them. Return the second layer’s output as embeddings, or normalize it for classification. section 3.1.2
- Train and validate the model, then inspect classification metrics and the similarity of learned embeddings for the task at hand. section 3.1
Listing 3.2 GCN class
class GCN(torch.nn.Module):
def __init__(self, in_channels, hidden_channels, out_channels):
super(GCN, self).__init__()
self.conv1 = GCNConv(in_channels, hidden_channels) #1
self.conv2 = GCNConv(hidden_channels, out_channels)
def forward(self, x, edge_index, \
return_embeds=False): #2
x = self.conv1(x, edge_index)
x = torch.relu(x) #3
x = self.conv2(x, edge_index)
if return_embeds: #4
return x
return torch.log_softmax(x, dim=1) #5
The two-layer class shows where `x` and `edge_index` enter each convolution and how the output switches between embeddings and class predictions. section 3.1.2
Products and recommendations
In the Amazon co-purchase graph, products are nodes and co-purchases are edges. A trained GCN predicts product categories; similarities between its product embeddings can also help identify potential bundles. For a recommendation use case at much larger scale, PinSage extends GCN ideas to a graph of pins and boards. section 3.1 section 1.3.1
A GCN is also a useful graph-aware baseline against models that use node features alone. Keep depth modest: more message-passing steps can make node representations too similar, an effect called over-smoothing. Full-graph processing can be costly; GraphSAGE instead uses neighborhood sampling and mini-batching to address that scaling constraint. section 4.3 section 3.6 section 7.6.1



