{"id":45600,"library":"node2vec","title":"node2vec","description":"Python implementation of the node2vec algorithm for learning continuous feature representations for nodes in networks. Version 0.5.0 supports Python 3.8-3.11, with sparse matrix input and optional GPU acceleration via CuPy.","status":"active","version":"0.5.0","language":"python","source_language":"en","source_url":"https://github.com/eliorc/node2vec","tags":["node2vec","graph-embeddings","networkx","word2vec"],"install":[{"cmd":"pip install node2vec","lang":"bash","label":"Standard install"},{"cmd":"pip install node2vec[gpu]","lang":"bash","label":"Install with GPU support (requires CuPy)"}],"dependencies":[{"reason":"Numerical arrays","package":"numpy","optional":false},{"reason":"Graph representation","package":"networkx","optional":false},{"reason":"Word2Vec implementation used for embedding","package":"gensim","optional":false},{"reason":"GPU acceleration (optional)","package":"cupy-cuda11x","optional":true},{"reason":"Progress bars","package":"tqdm","optional":false},{"reason":"Sparse matrix support","package":"scipy","optional":false}],"imports":[{"note":"Internal module path changed in 0.4.0; top-level import is recommended","wrong":"from node2vec.node2vec import Node2Vec","symbol":"Node2Vec","correct":"from node2vec import Node2Vec"},{"note":"Import the class directly to avoid attribute errors","wrong":"import node2vec; model = node2vec.Node2Vec(...)","symbol":"Node2Vec","correct":"from node2vec import Node2Vec"}],"quickstart":{"code":"import networkx as nx\nfrom node2vec import Node2Vec\n\n# Create a graph\ng = nx.karate_club_graph()\n\n# Precompute probabilities and generate walks\nnode2vec = Node2Vec(g, dimensions=64, walk_length=30, num_walks=200, workers=4)\n\n# Train Word2Vec model\nmodel = node2vec.fit(window=10, min_count=1, batch_words=4)\n\n# Get embedding for node 0\nembedding = model.wv['0']\nprint(embedding.shape)\n","lang":"python","description":"Basic usage: create a graph, generate walks, and train embeddings."},"warnings":[{"fix":"Replace 'target' with 'p' and 'q' in Node2Vec constructor.","message":"In v0.5.0, the 'target' parameter for biased walks is removed. Use 'p' and 'q' parameters to control return and in-out parameters.","severity":"breaking","affected_versions":">=0.5.0"},{"fix":"Convert node IDs to strings: nx.relabel_nodes(g, {n: str(n) for n in g.nodes()})","message":"Node identifiers must be strings. Passing non-string node IDs (e.g., integers) will cause a cryptic error in Gensim's Word2Vec.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the graph is a single connected component or handle missing nodes after training.","message":"Graph must be connected. Disconnected nodes will not appear in walks and embeddings will be missing.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace weight_key='weight' with edge_weight_attr='weight' in Node2Vec constructor.","message":"The 'weight_key' parameter for edge weights is deprecated and will be removed in a future version. Use 'edge_weight_attr' instead.","severity":"deprecated","affected_versions":">=0.5.0"}],"env_vars":null,"search_vec":"'-3.11':22 '0.5.0':18 '3.8':21 'acceler':30 'algorithm':7 'continu':10 'cupi':32 'embed':36 'featur':11 'gpu':29 'graph':35 'graph-embed':34 'implement':3 'input':26 'learn':9 'matrix':25 'network':16 'networkx':37 'node':14 'node2vec':1,6,33 'option':28 'python':2,20 'represent':12 'spars':24 'support':19 'version':17 'via':31 'word2vec':38","created_at":"2026-06-07T12:55:48.591410+00:00","updated_at":"2026-06-07T12:55:48.591410+00:00","problems":[{"fix":"Use 'from node2vec import Node2Vec'.","cause":"Importing the module instead of the class, or using outdated import path.","error":"AttributeError: module 'node2vec' has no attribute 'Node2Vec'"},{"fix":"Ensure all node lookups use the same type (string) as the graph nodes: model.wv[str(0)].","cause":"Trying to get embedding for a node that doesn't exist in the graph, or node IDs were converted to strings but lookup uses original type.","error":"ValueError: Node '0' not in graph"},{"fix":"Verify graph connectivity and ensure all nodes have at least one walk.","cause":"The node did not appear in any generated walks, likely because the graph is disconnected or node degree is zero.","error":"KeyError: \"Key '0' not in vocabulary\""},{"fix":"Upgrade: pip install --upgrade node2vec, then use from node2vec import Node2Vec.","cause":"Installed version is older than 0.4.0, where the class was not exposed at top level.","error":"ImportError: cannot import name 'Node2Vec' from 'node2vec'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/eliorc/node2vec","github":"https://github.com/eliorc/node2vec","docs":null,"changelog":null,"pypi":null,"npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}