{"data":{"slug":"eliorc-node2vec","name":"node2vec","tagline":"Implementation of the node2vec algorithm.","github_url":"https://github.com/eliorc/node2vec","owner":"eliorc","repo":"node2vec","owner_avatar_url":"https://avatars.githubusercontent.com/u/17727283?v=4","primary_language":"Python","stars":1301,"forks":253,"topics":["deep-learning","embeddings","machine-learning-algorithms"],"archived":false,"github_pushed_at":"2025-10-06T17:29:00+00:00","maintenance_label":"Slowing","stars_delta_30d":0,"url":"https://www.graphcanon.com/tools/eliorc-node2vec","markdown_url":"https://www.graphcanon.com/tools/eliorc-node2vec.md","api_url":"https://www.graphcanon.com/api/graphcanon/tools/eliorc-node2vec","graph_url":"https://www.graphcanon.com/api/graphcanon/graph?tool=eliorc-node2vec","description":"Implementation of the node2vec algorithm.","homepage_url":null,"license":"MIT","open_issues":0,"watchers":19,"ai_summary":"node2vec is an algorithmic framework for learning continuous feature representations for nodes in networks. It's a process used to create embeddings suitable for tasks such as link prediction, community detection, and other network analysis tasks.","readme_excerpt":"# Node2Vec\n\n\nPython3 implementation of the node2vec algorithm Aditya Grover, Jure Leskovec and Vid Kocijan.\n[node2vec: Scalable Feature Learning for Networks. A. Grover, J. Leskovec. ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD), 2016.](https://snap.stanford.edu/node2vec/)\n\n# Maintenance\n\n### I no longer have time to maintain this, if someone wants to pick the baton let me know\n\n## Installation\n\n`pip install node2vec`\n\n## Usage\n```python\nimport networkx as nx\nfrom node2vec import Node2Vec\n\n# Create a graph\ngraph = nx.fast_gnp_random_graph(n=100, p=0.5)\n\n# Precompute probabilities and generate walks - **ON WINDOWS ONLY WORKS WITH workers=1**\nnode2vec = Node2Vec(graph, dimensions=64, walk_length=30, num_walks=200, workers=4)  # Use temp_folder for big graphs\n\n# Embed nodes\nmodel = node2vec.fit(window=10, min_count=1, batch_words=4)  # Any keywords acceptable by gensim.Word2Vec can be passed, `dimensions` and `workers` are automatically passed (from the Node2Vec constructor)\n\n# Look for most similar nodes\nmodel.wv.most_similar('2')  # Output node names are always strings\n\n# Save embeddings for later use\nmodel.wv.save_word2vec_format(EMBEDDING_FILENAME)\n\n# Save model for later use\nmodel.save(EMBEDDING_MODEL_FILENAME)\n\n# Embed edges using Hadamard method\nfrom node2vec.edges import HadamardEmbedder\n\nedges_embs = HadamardEmbedder(keyed_vectors=model.wv)\n\n# Look for embeddings on the fly - here we pass normal tuples\nedges_embs[('1', '2')]\n''' OUTPUT\narray([ 5.75068220e-03, -1.10937878e-02,  3.76693785e-01,  2.69105062e-02,\n       ... ... ....\n       ..................................................................],\n      dtype=float32)\n'''\n\n# Get all edges in a separate KeyedVectors instance - use with caution could be huge for big networks\nedges_kv = edges_embs.as_keyed_vectors()\n\n# Look for most similar edges - this time tuples must be sorted and as str\nedges_kv.most_similar(str(('1', '2')))\n\n# Save embeddings for later use\nedges_kv.save_word2vec_format(EDGES_EMBEDDING_FILENAME)\n\n```\n\n### Parameters\n\n#### `node2vec.Node2vec`\n\n- `Node2Vec` constructor:\n    1. `graph`: The first positional argument has to be a networkx graph. Node names must be all integers or all strings. On the output model they will always be strings.\n    2. `dimensions`: Embedding dimensions (default: 128)\n    3. `walk_length`: Number of nodes in each walk (default: 80)\n    4. `num_walks`: Number of walks per node (default: 10)\n    5. `p`: Return hyper parameter (default: 1)\n    6. `q`: Input parameter (default: 1)\n    7. `weight_key`: On weighted graphs, this is the key for the weight attribute (default: 'weight')\n    8. `workers`: Number of workers for parallel execution (default: 1)\n    9. `sampling_strategy`: Node specific sampling strategies, supports setting node specific 'q', 'p', 'num_walks' and 'walk_length'.\n        Use these keys exactly. If not set, will use the global ones which were passed on the object initialization`\n    10. `quiet`: Boolean controlling the verbosity. (default: False)\n    11. `temp_folder`: String path pointing to folder to save a shared memory copy of the graph - Supply when working on graphs that are too big to fit in memory during algorithm execution.\n    12. `seed`: Seed for the random number generator (default: None). Deterministic results can be obtained if seed is set and `workers=1`.\n\n- `Node2Vec.fit` method:\n    Accepts any key word argument acceptable by gensim.Word2Vec\n\n#### `node2vec.EdgeEmbedder`\n\n`EdgeEmbedder` is an abstract class which all the concrete edge embeddings class inherit from.\nThe classes are `AverageEmbedder`, `HadamardEmbedder`, `WeightedL1Embedder` and `WeightedL2Embedder` which their practical definition could be found in the [paper](https://arxiv.org/pdf/1607.00653.pdf) on table 1\nNotice that edge embeddings are defined for any pair of nodes, connected or not and even node with itself.\n\n- Constructor:\n    1. `keyed_vectors`: A gensim.models.KeyedVectors instance c","github_created_at":"2017-12-08T13:30:06+00:00","created_at":"2026-07-11T11:31:00.057787+00:00","updated_at":"2026-08-22T12:01:25.635259+00:00","categories":[{"slug":"model-training","name":"Model Training","url":"https://www.graphcanon.com/categories/model-training","markdown_url":"https://www.graphcanon.com/categories/model-training.md","api_url":"https://www.graphcanon.com/api/graphcanon/categories/model-training"}],"tags":[{"slug":"deep-learning","name":"deep-learning"},{"slug":"embeddings","name":"embeddings"},{"slug":"machine-learning-algorithms","name":"machine-learning-algorithms"}],"trust":{"provenance":{"is_fork":false,"github_id":113577479,"owner_type":"User","methodology":"github_public_v1","parent_repo":null,"near_duplicate_slugs":[]},"computed_at":"2026-08-22T12:01:24.884Z","maintenance":{"label":"Slowing","score":36,"methodology":"github_public_v1","releases_90d":0,"days_since_push":319,"last_release_at":"2024-08-02T11:13:59Z","stars_delta_30d":0,"open_issues_delta_30d":0},"security_summary":{"status":"no_lockfile","scanner":null,"low_count":0,"high_count":0,"last_scan_at":"2026-07-11T11:31:02.036Z","medium_count":0,"scan_profile":"none","critical_count":0}},"capability_facts":{"scan":{"source":"repo_scan","observed_at":"2026-08-22T12:01:25.325Z"},"languages":{"value":["python"],"source":"github.language+pyproject.toml","observed_at":"2026-08-22T12:01:25.325Z"},"license_spdx":{"value":"MIT","source":"github.license","observed_at":"2026-08-22T12:01:25.325Z"}},"decision_facts":{"hosting":null,"pricing":null,"requirements":null,"constraints":null,"when_to_use":["- When you are dealing with network data and require embeddings that capture the structural role of nodes rather than their content.","- If your dataset involves complex networks where both depth-first and breadth-first traversals are important to understand node roles."],"when_not_to_use":["- Not suitable for datasets where understanding specific node attributes is more critical than network structure itself.","- Avoid if you only need embeddings based on shallow or flat graphs as node2vec can be computationally expensive with deeper graph explorations needed for its effectiveness."],"source":"enrich:decision_facts","observed_at":"2026-07-12T06:24:03.050Z"},"constraint_facets":null,"decision_summary":[{"label":"Adopt for","value":"node2vec is a Python implementation of an algorithmic framework that creates continuous feature representations for nodes in networks, useful for tasks such as link prediction and community detection."}]}}