{
 "id": "ep7b7js1q7",
 "slug": "node2vec",
 "title": "Node2vec",
 "updated": "2026-10-21",
 "topic_path": [
  {
   "id": "technology",
   "label": "Technology and the built world",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology"
  },
  {
   "id": "technology.computing",
   "label": "Computing and digital systems",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology.computing"
  },
  {
   "id": "technology.computing.ai",
   "label": "Artificial intelligence and data",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology.computing.ai"
  },
  {
   "id": "technology.computing.ai.ml_computation",
   "label": "Machine learning and neural computation",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology.computing.ai.ml_computation"
  },
  {
   "id": "technology.computing.ai.ml_methods",
   "label": "Machine learning methods",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology.computing.ai.ml_methods"
  },
  {
   "id": "technology.computing.ai.supervised_unsupervised",
   "label": "Supervised, unsupervised, and semi-supervised learning",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology.computing.ai.supervised_unsupervised"
  },
  {
   "id": "technology.computing.ai.supervised_unsupervised.dimensionality_reduction",
   "label": "Dimensionality reduction and manifold learning",
   "api_url": "https://www.edgepedia.org/api/v1/topics/technology.computing.ai.supervised_unsupervised.dimensionality_reduction"
  }
 ],
 "geo": [
  {
   "id": "geo.nongeo.t2001.technology.computing.ai.supervised_unsupervised",
   "label": "Non-geographic · 2001 to 2020: Supervised, unsupervised, and semi-supervised learning",
   "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology.computing.ai.supervised_unsupervised",
   "path": [
    {
     "id": "geo.nongeo",
     "label": "Non-geographic",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo"
    },
    {
     "id": "geo.nongeo.t2001",
     "label": "Non-geographic · 2001 to 2020",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001"
    },
    {
     "id": "geo.nongeo.t2001.technology",
     "label": "Technology and the built world",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology"
    },
    {
     "id": "geo.nongeo.t2001.technology.computing",
     "label": "Computing and digital systems",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology.computing"
    },
    {
     "id": "geo.nongeo.t2001.technology.computing.ai",
     "label": "Artificial intelligence and data",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology.computing.ai"
    },
    {
     "id": "geo.nongeo.t2001.technology.computing.ai.ml_computation",
     "label": "Machine learning and neural computation",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology.computing.ai.ml_computation"
    },
    {
     "id": "geo.nongeo.t2001.technology.computing.ai.ml_methods",
     "label": "Machine learning methods",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology.computing.ai.ml_methods"
    },
    {
     "id": "geo.nongeo.t2001.technology.computing.ai.supervised_unsupervised",
     "label": "Supervised, unsupervised, and semi-supervised learning",
     "api_url": "https://www.edgepedia.org/api/v1/geo/geo.nongeo.t2001.technology.computing.ai.supervised_unsupervised"
    }
   ]
  }
 ],
 "excerpt": "Node2vec is a graph embedding method that learns a low-dimensional vector for every node in a network by simulating biased random walks and training skip-gram on them.",
 "snippet": "Node2vec is a graph embedding method that learns a low-dimensional vector for every node in a network by simulating biased random walks and training skip-gram on them.",
 "node": "technology.computing.ai.supervised_unsupervised.dimensionality_reduction",
 "markdown": "# Node2vec\n\nNode2vec is a graph embedding method that learns a low-dimensional vector for every node in a network by simulating biased random walks and training a skip-gram (neural method predicting a word's neighbors to learn vectors) model on the resulting node sequences, so that nodes sharing network neighborhoods land near each other in the vector space.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> The output is a continuous feature representation of each node that can be fed to standard machine learning tools for classification, link prediction, and other downstream machine learning tasks.<sup>[2](http://snap.stanford.edu/node2vec/)</sup>\n\n| Key fact | Value |\n|---|---|\n| Output | One d-dimensional vector per node, used for downstream ML tasks<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n| Walk model | Second-order biased random walk with return parameter p and in-out parameter q<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n| Training objective | Skip-gram with negative sampling, optimized by asynchronous SGD<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n| Typical settings | d = 128, r = 10 walks per node, walk length l = 80, window k = 10, one epoch<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n| Reported gains | Up to 26.7% on multi-label classification and 12.6% on link prediction over prior methods<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n| Scalability | Linear in node count; one million nodes embedded in under four hours<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n| Relation to DeepWalk | DeepWalk is the special case p = 1, q = 1<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> |\n\n## How it works\n\nNode2vec optimizes a neighborhood-preserving objective: it learns a mapping of nodes to a low-dimensional feature space that maximizes the likelihood of preserving each node's network neighborhood, where the notion of \"neighborhood\" is flexible and controlled by the walk parameters.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> The framework balances an exploration-exploitation tradeoff that yields representations spanning a spectrum from homophily (similar nodes are connected) to structural equivalence (nodes play similar roles).<sup>[2](http://snap.stanford.edu/node2vec/)</sup>\n\nThe walk is a second-order [Markov chain](https://www.edgepedia.org/markov-chain): the transition probability \\( \\pi_{v,x} \\) depends on the previous node t in the walk, not only on the current node v.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> The unnormalized transition probability is\n\n\\[ \\pi_{v,x} = \\alpha_{pq}(t,x) \\cdot w_{vx} \\]\n\nwhere \\( w_{vx} \\) is the edge weight and the bias is\n\n\\[ \\alpha_{pq}(t,x) = \\begin{cases} 1/p & \\text{if } d_{tx} = 0 \\\\ 1 & \\text{if } d_{tx} = 1 \\\\ 1/q & \\text{if } d_{tx} = 2 \\end{cases} \\]\n\nwith \\( d_{tx} \\) the shortest-path distance between t and x, which is necessarily one of {0, 1, 2}.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup><sup> • </sup><sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup> The return parameter p controls the likelihood of immediately revisiting a node: high p (> max(q, 1)) discourages 2-hop redundancy, while low p (< min(q, 1)) makes the walk backtrack and stay local near its starting node.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> The in-out parameter q separates \"inward\" from \"outward\" nodes: q > 1 biases walks toward nodes close to the previous node, approximating breadth-first search, which a 2024 comparison credits with mapping the structural role of nodes; q < 1 encourages depth-first, outward exploration.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup><sup> • </sup><sup>[4](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0312863)</sup> Together, p and q interpolate between BFS-like and DFS-like exploration.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n\nThe sampled walks are then treated like sentences and fed to skip-gram. [Negative sampling](https://www.edgepedia.org/negative-sampling-machine-learning) replaces the softmax objective with a computationally cheaper binary classification objective over true pairs versus sampled negative pairs, rather than approximating the softmax normalizer, following word2vec practice.<sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup>\n\n## How it is done\n\nA practitioner runs three phases, each independently parallelizable.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n\n1. **Preprocessing.** Precompute the second-order transition probabilities; alias sampling then makes each walk step an O(1) operation, and it lets walks generalize to weighted networks with little preprocessing.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n2. **Walk sampling.** Simulate r random walks of length l from every node under the (p, q) bias.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n3. **Optimization.** Train skip-gram on the walks with negative sampling and asynchronous SGD, using window size k.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n\nThe reference settings are d = 128, r = 10, l = 80, k = 10, and a single epoch; p and q are grid-searched over {0.25, 0.50, 1, 2, 4} by 10-fold cross-validation on 10% of the labeled data.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> In the PyTorch Geometric implementation, the `context_size` parameter controls how many nodes of each sampled walk are actually used for gradient optimization in sliding windows.<sup>[5](https://pytorch-geometric.readthedocs.io/en/latest/tutorial/shallow_node_embeddings.html)</sup> The Neo4j Graph Data Science library exposes the same idea as `returnFactor` and `inOutFactor`.<sup>[6](https://neo4j.com/docs/graph-data-science/current/machine-learning/node-embeddings/node2vec/)</sup>\n\nSpace complexity is O(|E|) to store immediate neighbors plus \\( O(a^{2} \\cdot |V|) \\) for second-order walks, where a is the average degree.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> The method scales linearly with node count, generating representations for one million Erdős–Rényi nodes (average degree 10) in under four hours.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n\n## Origin\n\nNode2vec was published in the Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, under DOI 10.1145/2939672.2939754.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup><sup> • </sup><sup>[7](http://github.com/aditya-grover/node2vec)</sup> It builds on DeepWalk, the 2014 method by Bryan Perozzi, Rami Al-Rfou, and Steven Skiena that generalized language modeling from word sequences to graphs by treating truncated random walks as the equivalent of sentences.<sup>[8](https://doi.org/10.48550/arxiv.1403.6652)</sup> A 2023 review describes node2vec as a modified DeepWalk with two main changes: negative sampling instead of hierarchical softmax for normalization, which improves running time, and a biased random walk.<sup>[9](https://eprints.soton.ac.uk/485453/1/Baptista_2023_J._Phys._Complex._4_042001.pdf)</sup> DeepWalk's sampling strategy is exactly the special case p = 1, q = 1; LINE, another predecessor, learns d/2 dimensions by BFS-style simulation over immediate neighbors and d/2 by sampling nodes strictly at 2-hop distance.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n\n## Variants\n\n- **node2vec+**, introduced by Renming Liu, Matthew Hirn, and Arjun Krishnan in [Bioinformatics](https://www.edgepedia.org/bioinformatics) in 2023, accounts for edge weights when calculating walk biases and reduces to node2vec for unweighted graphs or unbiased walks; it ships in the PecanPy package.<sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup>\n- **dynnode2vec**, presented by Sedigheh Mahdavi, Shima Khoshraftar, and Aijun An in 2018 on arXiv, extends node2vec to dynamic networks by using previously learned embeddings as initial skip-gram weights and regenerating walks only for nodes that changed between timestamps, reducing running time; it is evaluated on link prediction, node classification, and anomaly detection.<sup>[10](https://doi.org/10.48550/arxiv.1812.02356)</sup>\n- **Het-node2vec**, by Giorgio Valentini and colleagues in 2021 on arXiv, adapts second-order walk sampling to heterogeneous multigraphs.<sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup> MetaPath2Vec extends Node2Vec to heterogeneous graphs by sampling walks along a metapath.<sup>[5](https://pytorch-geometric.readthedocs.io/en/latest/tutorial/shallow_node_embeddings.html)</sup>\n- **KG2Vec**, by YueQun Wang and colleagues in PLoS ONE in 2021, applies node2vec-style vectorization to knowledge graphs.<sup>[11](https://doi.org/10.1371/journal.pone.0248552)</sup>\n- **Scalable implementations** include PecanPy, a fast, parallelized, memory-efficient Python implementation by Renming Liu and Arjun Krishnan using cache-optimized compact graph structures,<sup>[12](https://github.com/krishnanlab/PecanPy)</sup> and Fast-Node2Vec, built on a Pregel-like framework, which achieves 7.7–122x speedups over Spark-Node2Vec on a 12-machine cluster and handles graphs with billions of vertices; the biased walk stage accounts for 98.8% of Spark-Node2Vec's runtime.<sup>[13](https://ar5iv.labs.arxiv.org/html/1805.00280)</sup>\n\n## Applications\n\nThe main uses are multi-label node classification and link prediction, the two tasks benchmarked in the original paper.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup> In computational biology, node2vec is widely used for gene function prediction, disease gene prediction, and essential protein prediction on genome-scale functional gene networks.<sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup>\n\n## Limitations and alternatives\n\nAs a shallow embedding method, node2vec trains one vector per node, so its parameter count grows as \\( O(|V| \\cdot d) \\); it cannot incorporate node or edge feature information, and it is transductive: nodes added after training get no representation without retraining or fine-tuning.<sup>[5](https://pytorch-geometric.readthedocs.io/en/latest/tutorial/shallow_node_embeddings.html)</sup> For rapidly updating graphs such as social networks or e-commerce platforms, graph neural networks are recommended because of their inductive bias, whereas shallow embeddings require frequent costly retrains.<sup>[14](https://data.mlr.press/assets/pdf/v02-24.pdf)</sup> On weighted graphs, plain node2vec cannot differentiate between small and large edges connecting the previous vertex to a potential next vertex, which degrades the intended walk bias; node2vec+ addresses this.<sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup>\n\nThe comparison with GNNs is not one-sided: in gene function and disease prediction on genome-scale functional gene networks with limited training data, both node2vec and node2vec+ outperformed GCN and [GraphSAGE](https://www.edgepedia.org/graphsage).<sup>[3](https://doi.org/10.1093/bioinformatics/btad047)</sup> Against its direct ancestors, node2vec generalizes DeepWalk (p = 1, q = 1) and subsumes LINE's BFS-style and 2-hop sampling within one parameterized walk.<sup>[1](https://dl.acm.org/doi/10.1145/2939672.2939754)</sup>\n\nRandom-walk methods remain an active research line after 2023: a 2024 study revisits walk-based learning on graphs, covering DeepWalk, node2vec, AWE, and CRaWl, the last of which replaces skip-gram with 1D CNNs over walks.<sup>[15](https://arxiv.org/html/2407.01214v2)</sup> The node2vec walks themselves have been analyzed theoretically and numerically as second-order Markov chains by mapping their transition rule.<sup>[16](https://ar5iv.labs.arxiv.org/html/2006.04904)</sup>\n\n## References\n\n1. [node2vec: Scalable Feature Learning for Networks (KDD 2016, publisher DOI record; merges arXiv:1607.00653 and the authors' Stanford PDF copies)](https://dl.acm.org/doi/10.1145/2939672.2939754)\n2. [node2vec (Stanford SNAP project page)](http://snap.stanford.edu/node2vec/)\n3. [Renming Liu, Matthew Hirn, Arjun Krishnan (2023). Accurately modeling biased random walks on weighted networks using node2vec+. Bioinformatics.](https://doi.org/10.1093/bioinformatics/btad047)\n4. [Comparing random walks in graph embedding and link prediction (PLOS One, 2024)](https://journals.plos.org/plosone/article?id=10.1371%2Fjournal.pone.0312863)\n5. [Shallow Node Embeddings, PyTorch Geometric documentation](https://pytorch-geometric.readthedocs.io/en/latest/tutorial/shallow_node_embeddings.html)\n6. [Node2Vec, Neo4j Graph Data Science documentation](https://neo4j.com/docs/graph-data-science/current/machine-learning/node-embeddings/node2vec/)\n7. [aditya-grover/node2vec (official reference implementation)](http://github.com/aditya-grover/node2vec)\n8. [Perozzi, Bryan, Al-Rfou, Rami, Skiena, Steven (2014). DeepWalk: Online Learning of Social Representations. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1403.6652)\n9. [Zoo guide to network embedding (J. Phys. Complex., 2023)](https://eprints.soton.ac.uk/485453/1/Baptista_2023_J._Phys._Complex._4_042001.pdf)\n10. [Mahdavi, Sedigheh, Khoshraftar, Shima, An, Aijun (2018). dynnode2vec: Scalable Dynamic Network Embedding. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1812.02356)\n11. [YueQun Wang and colleagues (2021). KG2Vec: A node2vec-based vectorization model for knowledge graph. PLoS ONE.](https://doi.org/10.1371/journal.pone.0248552)\n12. [krishnanlab/PecanPy](https://github.com/krishnanlab/PecanPy)\n13. [Efficient Graph Computation for Node2Vec (Fast-Node2Vec)](https://ar5iv.labs.arxiv.org/html/1805.00280)\n14. [SEESAW: Do Graph Neural Networks Improve Node Representation Learning for All? (PMLR)](https://data.mlr.press/assets/pdf/v02-24.pdf)\n15. [Revisiting Random Walks for Learning on Graphs (2024)](https://arxiv.org/html/2407.01214v2)\n16. [Analysis of node2vec random walks on networks](https://ar5iv.labs.arxiv.org/html/2006.04904)\n\n---\n*Topic: Encyclopedia › Technology and the built world › Computing and digital systems › Artificial intelligence and data › Machine learning and neural computation › Machine learning methods › Supervised, unsupervised, and semi-supervised learning › Dimensionality reduction and manifold learning*\n\n*Initially written Sep 29, 2026 · Edited: Oct 15, 2026; Oct 21, 2026*\n\n*Copyright 2026 EdgeChat AI, a subsidiary of Biostate AI.*\n\nLicense: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license\n",
 "same_as": [],
 "url": "https://www.edgepedia.org/node2vec",
 "markdown_url": "https://www.edgepedia.org/node2vec.md",
 "license": {
  "name": "Edgepedia Community License 1.0",
  "url": "https://www.edgepedia.org/edgepedia/license",
  "summary": "Free with credit, commercial use included. AI training is open to everyone. For other uses, organizations over USD 100M in revenue or 100M monthly users license separately.",
  "spdx": "LicenseRef-Edgepedia-Community-1.0"
 },
 "credit": "\"Node2vec\", Edgepedia (EdgeChat), https://www.edgepedia.org/node2vec. Edgepedia Community License 1.0.",
 "credit_md": "\"[Node2vec](https://www.edgepedia.org/node2vec)\", Edgepedia (EdgeChat), [https://www.edgepedia.org/node2vec](https://www.edgepedia.org/node2vec). [Edgepedia Community License 1.0](https://www.edgepedia.org/edgepedia/license).",
 "credit_html": "\"<a href=\"https://www.edgepedia.org/node2vec\">Node2vec</a>\", Edgepedia (EdgeChat), <a href=\"https://www.edgepedia.org/node2vec\">https://www.edgepedia.org/node2vec</a>. <a href=\"https://www.edgepedia.org/edgepedia/license\">Edgepedia Community License 1.0</a>.",
 "speakable": "Node2vec is a graph embedding method that learns a low-dimensional vector for every node in a network by simulating biased random walks and training skip-gram on them."
}
