# node2vec: Scalable Feature Learning for Networks

node2vec learns node features by sampling neighborhoods with biased random walks

Aditya Grover, Jure Leskovec · arXiv · 2016-7-3

- **Problem** Earlier unsupervised node embedding methods fix one rigid notion of neighborhood. That misses the mix of community and structural role patterns that real networks show.
- **Method** node2vec steers a biased random walk with p and q to sample neighborhoods.
- **Results** On BlogCatalog, node2vec scored 0.2581 Macro-F1, compared to 0.2110 for DeepWalk.

## Why network features are hard to learn

Prediction over nodes and edges starts with a feature vector for every node and edge. Hand-engineered features are tailored to one task, so they rarely carry over to another. Learning the features instead is the alternative, and the hard part is choosing the objective.

A supervised objective fits the downstream task well, but it adds so many parameters that training becomes slow. A purely unsupervised objective is cheaper to optimize, which is the route the authors take. The classic unsupervised route, dimensionality reduction, needs eigendecomposition, which is expensive on large networks. Its latent representations also perform poorly on prediction tasks over networks.

Recent methods that preserve local neighborhoods are efficient, but each one fixes a single notion of neighborhood. Because that notion is rigid, these methods stay largely insensitive to connectivity patterns that are specific to networks. No single sampling strategy wins across all networks and all prediction tasks, so a fixed strategy is a real shortcoming.

Nodes can be grouped by community, which is homophily, or by structural role, which is structural equivalence. In Figure 1, u and s1 share a community, while u and s6 share the role of a hub. Real networks usually mix both principles, so a useful method has to capture both.

## Biased walks as a flexible neighborhood

The key idea is to define a node's neighborhood by a random walk that can be steered. Two parameters tilt the walk toward staying local or moving outward, so one sampler can imitate either extreme. The walk, not a fixed rule, decides which nodes count as the neighborhood.

The two extremes are breadth-first sampling, which keeps only immediate neighbors, and depth-first sampling, which moves away from the source. For a neighborhood of three nodes around u in Figure 1, BFS takes s1, s2 and s3, while DFS takes s4, s5 and s6. BFS suits structural equivalence because a node's role can be read from its immediate surroundings, but it sees only a small part of the graph.

DFS covers more of the network and suits homophily, but its samples vary more and can be less representative.

The walk starts at a source node u and runs for a fixed length l, with each next node drawn from unnormalized transition weights. The weight of each step depends on the node visited just before the current one, which makes the walk second order. For an edge from v to x, the weight is \\( \\pi\_{vx} = \\alpha\_{pq}(t,x) \\cdot w\_{vx} \\), where t is the previous node and \\( w\_{vx} \\) is the static edge weight.

The bias \\( \\alpha\_{pq}(t,x) \\) equals \\( 1/p \\) when x is t itself, 1 when x is a neighbor of t, and \\( 1/q \\) when x is two hops from t. The weights are divided by a normalizing constant Z to give the step probabilities.

The return parameter p controls how often the walk immediately returns to t, and a high p makes that less likely. The in-out parameter q decides whether the walk stays near t or leaves it, with q above 1 keeping it close and q below 1 pushing it outward. Setting p and q to 1 gives the uniform walk of DeepWalk, which is why DeepWalk is a special case of node2vec.

## From walks to node features

Each node's feature vector is fit so that it predicts the nodes in its sampled neighborhood, following the Skip-gram idea. The objective maximizes the sum over nodes of the log-probability of each neighborhood given the node's features. \\\[ \\max\_f \\sum\_{u \\in V} \\log \\Pr(N\_S(u) \\mid f(u)) \\\] Two simplifying assumptions make this tractable: neighbors are conditionally independent given the source, and each source-neighbor pair is scored by a softmax over dot products.

The per-node partition function \\( Z\_u = \\sum\_{v \\in V} \\exp(f(u)\\cdot f(v)) \\) is expensive for large graphs. Negative sampling approximates it, and the objective is optimized by stochastic gradient ascent over the feature parameters.

The pipeline has three phases: compute transition weights, simulate walks, and then optimize the features. From every node the method simulates r walks of length l, so each node starts r walks. Each step draws the next node by alias sampling, which takes constant time once the transition weights are precomputed. A single walk of length l \> k yields k samples for each of l - k nodes, so the samples are reused.

The default settings in the experiments are d = 128, r = 10, l = 80 and k = 10, with one optimization epoch.

For link prediction the method needs a representation of a node pair, so it combines the two node feature vectors with a binary operator. Table 1 lists four operators: average, Hadamard (element-wise product), weighted-L1 and weighted-L2. Each operator keeps the dimension at d, and the authors define them for any pair of nodes, whether or not an edge exists.

## Les Misérables case study

The authors use a character coappearance network from Les Misérables, with 77 nodes and 254 edges. They learn 16-dimensional features (d = 16), cluster them with k-means, and color the network by cluster. With p = 1 and q = 0.5, the colors follow communities of characters who interact in the same sub-plots.

With p = 1 and q = 2, the clusters follow the roles the authors call bridges and periphery. The blue cluster holds characters who bridge sub-plots, and the yellow cluster holds peripheral characters with few interactions. This evidence is visual and qualitative, so it shows that the parameters move the clusters but gives no score for either assignment.

## Multi-label classification results

The authors feed node features into one-vs-rest logistic regression with L2 regularization and split the data over 10 random instances. The p and q values are tuned on 10% labeled data over the grid {0.25, 0.5, 1, 2, 4}, and the authors report a p-value below 0.01 over 10 seeds. To keep the comparison fair, each method generates an equal number of samples, and DeepWalk is switched to negative sampling.

On BlogCatalog with 50% of nodes labeled, node2vec scored 0.2581 Macro-F1, compared to 0.2110 for DeepWalk. That is a gain of 22.3% over DeepWalk, and the gain over LINE on the same network is 229.2%. The authors attribute LINE's weak showing to its inability to reuse samples, which random walks allow.

Over LINE on PPI the gain is 23.8%.

Varying the labeled fraction from 10% to 90% shows node2vec ahead of DeepWalk and LINE on most networks. The largest gain over DeepWalk is 26.7% on BlogCatalog at 70% labeled data. Gains over LINE reach 41.1% on PPI when only 10% of the nodes are labeled.

## Link prediction results

Positive examples are edges removed at random while the residual network stays connected, and negative examples are node pairs with no edge. The heuristics Common Neighbors, Jaccard's Coefficient, Adamic-Adar and Preferential Attachment score each pair from the neighbor sets of its two nodes. The authors test on Facebook with 4,039 nodes and 88,234 edges, along with PPI and arXiv ASTRO-PH.

On arXiv the AUC improvement of node2vec over the best baseline, Adamic-Adar, is 12.6%. With the Hadamard operator node2vec scores 0.9680 AUC on Facebook, which equals DeepWalk and is above Jaccard's Coefficient at 0.8880. With the average operator the heuristics stay ahead on Facebook, with node2vec at 0.7266, so the choice of operator matters.

Across the three networks, node2vec beats DeepWalk and LINE, with gains up to 3.8% and 6.5% at each algorithm's best operator. The exceptions are a couple of cases with the Weighted-L1 and Weighted-L2 operators, where LINE does better. The Hadamard operator is the most stable choice for node2vec and gives the best average across the networks.

## Sensitivity, perturbation and scale

On BlogCatalog with a 50-50 split, one parameter is varied at a time while the others keep defaults, with p and q at 1 by default. Performance improves as p and q decrease, which the authors link to the homophily and structural equivalence they expect in BlogCatalog. Macro-F1 tends to saturate once the feature dimension reaches around 100.

More walks per node and longer walks help, which is expected from the larger sampling budget, and a larger context size k helps at the cost of longer optimization.

When edges are removed at random with the number of connected components held fixed, Macro-F1 falls roughly linearly with a small slope. When noisy edges are added between random node pairs, the score drops faster at first, and then the decline slows down. The authors frame both results as relevant to evolving networks and to networks built from noisy measurements.

On Erdos-Renyi graphs with constant average degree 10, runtime grows roughly linearly with the number of nodes. One million nodes take less than four hours, and preprocessing is negligibly small compared with the walks. Negative sampling and asynchronous SGD keep the optimization phase efficient.

## Limitations and open questions

Reusing walk samples across source nodes can introduce some bias, although the authors observe that it greatly improves efficiency. BFS explores only a very small part of the graph for a given k, and DFS has high variance when the neighborhood is large. Tuning p and q needs labeled data, so the method is semi-supervised rather than fully unsupervised.

The experiments use three multi-label networks, BlogCatalog, PPI and Wikipedia, and three link prediction networks, Facebook, PPI and arXiv ASTRO-PH. The parameter search uses one grid and 10% labeled data, and the paper does not test other grids or label fractions for it. The authors leave open heterogeneous networks, networks with domain features, signed edges, and why the Hadamard operator works best.

## Paper info

- **Authors**: Aditya Grover, Jure Leskovec
- **Venue**: arXiv · Preprint
- **First published**: 2016-7-3
- **Added**: 2026-11-11
- **Updated**: 2016-7-3
- **Version**: v1
- **arXiv**: 1607.00653
- **Category**: cs.SI · cs.LG · stat.ML
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1607.00653v1) · [PDF ↗](https://arxiv.org/pdf/1607.00653v1)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Aditya Grover, Jure Leskovec (2016). node2vec: Scalable Feature Learning for Networks. arXiv:1607.00653v1. https://arxiv.org/abs/1607.00653v1

**BibTeX**

```
@misc{grover2016node2vec,
  title = {{node2vec: Scalable Feature Learning for Networks}},
  author = {Aditya Grover and Jure Leskovec},
  year = {2016},
  eprint = {1607.00653},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1607.00653v1}
}
```

## Other paper commentary

- [Explainable Artificial Intelligence (XAI): Concepts, Taxonomies, Opportunities and Challenges toward Responsible AI](https://refivu.com/en/papers/3f686a20-03db-4642-80bb-f85fafc1d04f-explainable-artificial-intelligence-xai-concepts-taxonomies.md)
- [Intriguing properties of neural networks](https://refivu.com/en/papers/5d9b1ffd-1b1d-4795-87df-32680ad74683-intriguing-properties-of-neural-networks.md)
- [Empirical Evaluation of Gated Recurrent Neural Networks on Sequence Modeling](https://refivu.com/en/papers/136a3b1f-3eb6-469b-8a8a-7536056851d5-empirical-evaluation-of-gated-recurrent-neural-networks-on.md)
- [Convolutional Neural Networks for Sentence Classification](https://refivu.com/en/papers/e03eeb97-8544-4ef6-a8e6-47276e072373-convolutional-neural-networks-for-sentence-classification.md)
- [Deep Learning in Neural Networks: An Overview](https://refivu.com/en/papers/fc7c2f1e-9030-4a55-892b-82a89ff398b7-deep-learning-in-neural-networks-an-overview.md)
- [Two-Stream Convolutional Networks for Action Recognition in Videos](https://refivu.com/en/papers/d621dee0-0b2a-45a8-b152-6260b98f0db4-two-stream-convolutional-networks-for-action-recognition-in.md)
- [V-Net: Fully Convolutional Neural Networks for Volumetric Medical Image Segmentation](https://refivu.com/en/papers/a6e119c3-3c19-41b0-afee-c1d81e538a35-v-net-fully-convolutional-neural-networks-for-volumetric.md)
- [Stop Explaining Black Box Machine Learning Models for High Stakes Decisions and Use Interpretable Models Instead](https://refivu.com/en/papers/96d240ca-7c32-4f79-8167-c2beafc2a38f-stop-explaining-black-box-machine-learning-models-for.md)
- [Aggregated Residual Transformations for Deep Neural Networks](https://refivu.com/en/papers/e793fb66-bc1f-4ced-89ed-5f634b4590ea-aggregated-residual-transformations-for-deep-neural-networks.md)
- [Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network](https://refivu.com/en/papers/5a2dbd66-c794-464b-9d10-02f19eeb20e7-photo-realistic-single-image-super-resolution-using-a.md)
- [UMAP: Uniform Manifold Approximation and Projection for Dimension Reduction](https://refivu.com/en/papers/44ccc549-6643-4369-889c-f60f3d61cbf4-umap-uniform-manifold-approximation-and-projection-for.md)
- [Representation Learning: A Review and New Perspectives](https://refivu.com/en/papers/b38149f8-9f53-4406-8d25-bb93c21c4bc9-representation-learning-a-review-and-new-perspectives.md)

## Terms in this paper

- [Stochastic Gradient Descent](https://refivu.com/en/terms/a49650824022-stochastic-gradient-descent)
- [AUC](https://refivu.com/en/terms/017a335bbf0e-auc)
- [Negative sampling](https://refivu.com/en/terms/1dbdea971d8c-negative-sampling)
- [Wikipedia](https://refivu.com/en/terms/2569175e3d90-wikipedia)
- [link prediction](https://refivu.com/en/terms/f029f4345f8f-link-prediction)
- [Macro-F1](https://refivu.com/en/terms/bac7d2670b4d-macro-f1)
- [Micro-F1](https://refivu.com/en/terms/984be90cfb2a-micro-f1)
- [spectral clustering](https://refivu.com/en/terms/21fd8dbd5474-spectral-clustering)
- [BLOGCATALOG](https://refivu.com/en/terms/8a1839cb1f57-blogcatalog)
- [node2vec](https://refivu.com/en/terms/56209922221d-node2vec)
- [Skip-gram](https://refivu.com/en/terms/e835a0cf8e3d-skip-gram)
- [BFS](https://refivu.com/en/terms/9a7edf36d427-bfs)
- [DFS](https://refivu.com/en/terms/a0b56dde754a-dfs)
- [homophily](https://refivu.com/en/terms/a97eac81d52a-homophily)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/dc0725e4-ec21-4d60-9363-0eac2fc69a10-node2vec-scalable-feature-learning-for-networks)
