Inductive Representation Learning on Large Graphs
- Publication
- NeurIPS 2017Conference
- First submitted to arXiv
- arXiv:1706.02216
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{graphlearninggraphsage2017,
title = {{Inductive Representation Learning on Large Graphs}},
author = {William L. Hamilton and Rex Ying and Jure Leskovec},
year = {2017},
eprint = {1706.02216},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1706.02216}
}
New Reddit posts arrive every minute, new YouTube videos every day. A recommender needs representations for these new nodes, ideally immediately, without retraining the whole graph.
Before 2017, mainstream node embeddings could not do this. DeepWalk and node2vec learn a separate vector for each node, like a lookup table; a new node has no entry. GCN consumes node features, but its paper trains on the whole graph, keeping the full adjacency matrix in memory at every step.
William Hamilton, Rex Ying and Jure Leskovec at Stanford change the learning target. Instead of learning each node's vector, learn a function that computes a vector from its neighbors. Once trained, it applies directly to any new node with features and neighbors.
Defining the Problem
Transductive and Inductive
The paper distinguishes two settings.
In the transductive setting, the whole graph is visible during training, though some nodes have no labels; the GCN paper's semi-supervised classification fits here. In the inductive setting, unseen nodes, or even entirely new graphs, arrive after training.
The authors consider induction harder. The model must learn to identify a node's role from local structure and features, rather than memorize its position. It must also place unseen nodes in a space consistent with existing ones, without seeing them during training.
Most existing embeddings are transductive. Extending them to new nodes requires more optimization at test time, which is slow.
Too Many Neighbors
The second problem is scale. The paper's Reddit dataset has 232,965 posts, connecting any two commented on by the same user. Each post has 492 edges on average.
If every node examines its full two-hop neighborhood, one node can involve hundreds of thousands of others, making batch memory and runtime unpredictable.
Solving the Problem
The Algorithm
GraphSAGE stands for SAmple and aggreGatE. The forward pass runs for rounds, each performing three operations per node :
Aggregate neighboring representations into one vector, concatenate it with the node's own representation from the previous round, multiply by a weight matrix, apply a nonlinearity, then L2-normalize. contains the input features; round outputs the node embedding.
Concatenation is the main difference from GCN. GCN treats the node itself as another neighbor and takes a weighted average, sharing one among everyone. GraphSAGE separates self and neighbors, effectively giving each its own weights. The authors describe this as a kind of skip connection across depths, with substantial experimental benefits.

Sample the Neighbors
is a fixed-size uniform sample, resampled each round, rather than the full neighborhood. Sampling neighbors in round fixes batch cost at . The authors find and work well; experiments use and .
Take Reddit. With sampling, one target node touches at most nodes. The average degree is 492, so without sampling the two-hop upper bound is , about 242,000 nodes. That is only a rough bound that does not remove repeated neighbors, but it already exceeds the 232,965 nodes in the whole dataset. Without sampling, computing one node's two-layer representation means reading nearly the entire graph.
For minibatch training, the authors first sample the required neighborhoods outward from target nodes, then compute inward layer by layer, evaluating only nodes actually needed by the recursion.
Now run one layer on a six-node graph, sampling 2 neighbors per node with a mean aggregator:
import numpy as np
np.set_printoptions(precision=2, suppress=True)
rng = np.random.default_rng(0)
neighbors = [[1, 2], [0, 2, 3], [0, 1, 3, 4, 5], [1, 2], [2], [2]]
h = rng.random((6, 3)) # 6 nodes, 3 features each
W = rng.normal(size=(4, 6)) # 6 concatenated dimensions to 4 output dimensions
def sage_layer(h, neighbors, W, S):
out = []
for v, nbrs in enumerate(neighbors):
picked = rng.choice(nbrs, size=S, replace=len(nbrs) < S) # Sample with replacement if there are too few neighbors
h_nb = h[picked].mean(0) # Mean aggregation
z = np.maximum(W @ np.concatenate([h[v], h_nb]), 0) # Concatenate self and neighbors, then multiply by W
out.append(z / (np.linalg.norm(z) + 1e-12)) # L2 normalization
return np.array(out)
h1 = sage_layer(h, neighbors, W, S=2)
print(h1.shape)
print(h1)
(6, 4)
[[0.96 0.12 0. 0.24]
[0.74 0. 0.19 0.64]
[0.99 0. 0. 0.16]
[0.95 0.3 0. 0. ]
[0.71 0. 0. 0.7 ]
[0.81 0. 0.13 0.57]]
Node 2 has five neighbors but samples only two at a time. Nodes 4 and 5 have one neighbor each, so sampling repeats it. The official TensorFlow implementation similarly builds a fixed-length neighbor table per node, sampling with replacement to fill short neighborhoods, then randomly selects entries for each batch.
Weights are independent of node identity. A new node with features and neighbors can therefore use the same sage_layer directly.
Three Aggregators
Neighbors have no order, so an aggregator should ideally be permutation invariant, trainable and expressive. The authors try three:
- Mean: elementwise averaging. They also make a GCN-style variant that omits self-concatenation and instead averages before weighting, calling it the convolutional aggregator.
- LSTM: the most expressive, but inherently order-sensitive. The compromise is to shuffle neighbors randomly before each input.
- Pooling: pass every neighbor independently through a fully connected layer, then take an elementwise maximum, . Replacing max with mean makes little difference, the authors report.
Learning without Labels
Without task labels, GraphSAGE uses a graph-based loss:
appears near on a fixed-length random walk, is a negative sample, and is the number of negatives. This resembles DeepWalk's objective, but is computed from neighboring features rather than retrieved from a table. With labels, replace or augment this loss with cross-entropy.
The Connection to WL
The authors also note that setting to the number of nodes, weights to identity matrices and the aggregator to a hash function turns Algorithm 1 into the Weisfeiler–Lehman graph-isomorphism test. GraphSAGE can be viewed as a continuous WL approximation whose purpose is useful node representations rather than isomorphism testing.
Discussion
Three Datasets
All experiments use inductive settings:
- Citation network: 302,424 Web of Science papers from six biology-related fields, 2000–2005, with average degree 9.15. Train on 2000–2004 and predict fields of 2005 papers.
- Reddit: September 2014 posts from 50 large subreddits. Train on the first 20 days and predict later posts' subreddits.
- PPI: protein–protein interaction graphs, one per human tissue. Train on 20 graphs, validate on 2 and test on 2, predicting 121 protein-function labels. Test graphs are entirely unseen during training.
Main Results
| Method | Citation network | PPI | |
|---|---|---|---|
| Raw features | 0.575 | 0.585 | 0.422 |
| DeepWalk + features | 0.701 | 0.691 | — |
| GraphSAGE-GCN | 0.772 | 0.930 | 0.500 |
| GraphSAGE-mean | 0.820 | 0.950 | 0.598 |
| GraphSAGE-LSTM | 0.832 | 0.954 | 0.612 |
| GraphSAGE-pool | 0.839 | 0.948 | 0.600 |
These are micro-F1 scores for supervised variants. The GCN-style aggregator finishes last on all three datasets, nearly 0.1 behind the others on PPI. Its main difference from mean is the missing concatenation of self and neighbors.
A Wilcoxon test across six settings—supervised and unsupervised on three datasets—finds LSTM, pool and mean significantly better than the GCN-style aggregator, with no significant difference between LSTM and pool. The authors acknowledge the limited statistical power of only six settings.
Even the authors are somewhat surprised that LSTM, designed for sequences, works so well on unordered neighborhoods.
Speed and Sampling Tradeoffs

On the left, training times are similar, with GraphSAGE-LSTM slowest. At test time, however, DeepWalk must rerun random walks and SGD for new nodes, taking 100 to 500 times longer than GraphSAGE.
On the right, more sampled neighbors improve F1, but returns diminish quickly while time keeps rising. The authors also find improves over by 10% to 15% on average; increasing to adds only 0% to 5% while multiplying runtime by 10 to 100.
What Came Next
The paper ends by pointing to follow-up work by Chen and Zhu for better PPI results: they specifically tune GraphSAGE's hyperparameters for PPI and add dropout, layer normalization and a new sampling scheme.
The following year, Rex Ying, Hamilton and Leskovec work with Pinterest on PinSage, training with 7.5 billion examples on a graph of 3 billion nodes and deploying it as Pinterest's recommendation engine. PinSage abstract
Conclusion
GraphSAGE makes a graph neural network learn a function rather than a lookup table. Sampling fixes batch cost, enabling minibatch training on large graphs; weighting self and neighbors separately gives a substantial gain over GCN-style averaging.
For your own large graph, start with , , and a mean aggregator as the baseline. PyTorch Geometric provides SAGEConv and its companion NeighborLoader, so sampling and minibatching need no custom implementation.