node2vec logo

node2vec

eliorc/node2vec

Implementation of the node2vec algorithm.

GraphCanon updated 3d · GitHub synced 3d

1.3k stars253 forksLast push 10mo Python MIT

Decision brief

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.

Good fit when

  • - 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.

Avoid when

  • - 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.

Observed Jul 12, 2026 · Source: enrich:decision_facts

Verify the decision

Maintenance and security

Full trust report
Maintenance
Slowing (319d since push)
As of 3d
Provenance
Not a fork · Personal account
As of 3d
Security (OSV)
No lockfile
As of 1mo

Public GitHub metadata and optional OSV scans. Signals, not a guarantee. Trust methodology.

Install

pip install node2vec
PyPI

Similar tools

Same-category neighbours. No typed graph edges are catalogued for this tool yet.

Evidence and technical details

Sourced facts, taxonomy, compatibility claims, README excerpt, and machine-readable endpoints.

Overview

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.

Capability facts

Languages
python

Source: github.language+pyproject.toml · Aug 22, 2026

Categories

Compatibility

Sourced claims from the README excerpt - not unsourced marketing copy.

Python runtimePython

Source: README excerpt (regex_v1, Aug 22, 2026)

Python3 implementation of the node2vec algorithm Aditya Grover, Jure Leskovec and Vid K
Source link

Tags

README

Node2Vec

Python3 implementation of the node2vec algorithm Aditya Grover, Jure Leskovec and Vid Kocijan. node2vec: Scalable Feature Learning for Networks. A. Grover, J. Leskovec. ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD), 2016.

Maintenance

I no longer have time to maintain this, if someone wants to pick the baton let me know

Installation

pip install node2vec

Usage

import networkx as nx
from node2vec import Node2Vec

# Create a graph
graph = nx.fast_gnp_random_graph(n=100, p=0.5)

# Precompute probabilities and generate walks - **ON WINDOWS ONLY WORKS WITH workers=1**
node2vec = Node2Vec(graph, dimensions=64, walk_length=30, num_walks=200, workers=4)  # Use temp_folder for big graphs

# Embed nodes
model = 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)

# Look for most similar nodes
model.wv.most_similar('2')  # Output node names are always strings

# Save embeddings for later use
model.wv.save_word2vec_format(EMBEDDING_FILENAME)

# Save model for later use
model.save(EMBEDDING_MODEL_FILENAME)

# Embed edges using Hadamard method
from node2vec.edges import HadamardEmbedder

edges_embs = HadamardEmbedder(keyed_vectors=model.wv)

# Look for embeddings on the fly - here we pass normal tuples
edges_embs[('1', '2')]
''' OUTPUT
array([ 5.75068220e-03, -1.10937878e-02,  3.76693785e-01,  2.69105062e-02,
       ... ... ....
       ..................................................................],
      dtype=float32)
'''

# Get all edges in a separate KeyedVectors instance - use with caution could be huge for big networks
edges_kv = edges_embs.as_keyed_vectors()

# Look for most similar edges - this time tuples must be sorted and as str
edges_kv.most_similar(str(('1', '2')))

# Save embeddings for later use
edges_kv.save_word2vec_format(EDGES_EMBEDDING_FILENAME)

Parameters

node2vec.Node2vec

  • Node2Vec constructor:

    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.
    2. dimensions: Embedding dimensions (default: 128)
    3. walk_length: Number of nodes in each walk (default: 80)
    4. num_walks: Number of walks per node (default: 10)
    5. p: Return hyper parameter (default: 1)
    6. q: Input parameter (default: 1)
    7. weight_key: On weighted graphs, this is the key for the weight attribute (default: 'weight')
    8. workers: Number of workers for parallel execution (default: 1)
    9. sampling_strategy: Node specific sampling strategies, supports setting node specific 'q', 'p', 'num_walks' and 'walk_length'. Use these keys exactly. If not set, will use the global ones which were passed on the object initialization`
    10. quiet: Boolean controlling the verbosity. (default: False)
    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.
    12. seed: Seed for the random number generator (default: None). Deterministic results can be obtained if seed is set and workers=1.
  • Node2Vec.fit method: Accepts any key word argument acceptable by gensim.Word2Vec

node2vec.EdgeEmbedder

EdgeEmbedder is an abstract class which all the concrete edge embeddings class inherit from. The classes are AverageEmbedder, HadamardEmbedder, WeightedL1Embedder and WeightedL2Embedder which their practical definition could be found in the paper on table 1 Notice that edge embeddings are defined for any pair of nodes, connected or not and even node with itself.

  • Constructor:
    1. keyed_vectors: A gensim.models.KeyedVectors instance c

For agents

This page has a .md twin and JSON over the API.

Was this helpful?

Anonymous feedback helps us improve pages and translations.