liveBook · Manning

NeighborLoader

As explained in Graph Neural Networks in Action

NeighborLoader is a PyTorch Geometric data loader that samples node neighborhoods and produces mini-batches for graph learning.

NeighborLoader is a PyTorch Geometric loader for training graph neural networks with mini-batches. Instead of aggregating every node and edge at once, it samples local neighborhoods around selected input nodes, reducing memory pressure for attention-heavy models such as GAT. section 4.4.1 section 7.7.2

A typical NeighborLoader workflow is:

  • Set input_nodes to the training mask or training-node indices so batches begin from the intended supervision set. section 7.7.2
  • Specify num_neighbors for each message-passing layer; num_neighbors=[1000]*2 samples up to 1,000 neighbors across two iterations. section 4.4.1
  • Iterate over sampled batches, move features, labels, and adjacency information to the device, then run the forward pass, loss, backpropagation, and optimizer update. section 7.7.2

Mini-batching a fraud-detection GAT

A loader can be created with batch_size=128, num_neighbors=[1000]*2, and input_nodes=data.train_mask. Calling next(iter(loader)) returns sampled_data, whose batch_size and label distribution can be inspected before passing the batch to a GAT. This approach supports fake-review detection while avoiding full-graph attention memory requirements. section 4.4.1 section 4.0

How Graph Neural Networks in Action covers it

How deep it goes
Defines input nodes, batch size, and per-layer neighbor counts, then demonstrates sampled-batch training and device transfer.
Examples
Uses 128-node batches and two-layer sampling for Yelp fake-review fraud detection.
What it assumes
Assumes graph data, node features, labels, training-node selection, and a GNN training loop.
What you can do after
Apply it via PyTorch Geometric to train GNNs on sampled neighborhoods instead of complete graphs.
How it connects
Connects neighborhood aggregation with GAT, GNN layers, mini-batch training, GPU execution, and alternative PyTorch Geometric samplers.

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.