Skip to content
Graph Intelligence Hub
Menu

Algorithm

node2vec

activeNeeds verification

Learns node embeddings by running biased second-order random walks and training a skip-gram model on them, trading off local and global structure.

Intuition

Treat random walks as sentences and nodes as words, then use word2vec; parameters p and q make walks more BFS-like or DFS-like.

Complexity

TimeO(r · l · V) walk generation plus skip-gram training
SpaceO(V · d)

Python

from torch_geometric.nn import Node2Vec
model = Node2Vec(data.edge_index, embedding_dim=128, walk_length=20,
                 context_size=10, walks_per_node=10, p=1.0, q=1.0)

Cypher (Neo4j GDS)

CALL gds.node2vec.stream('myGraph', {embeddingDimension: 128})
YIELD nodeId, embedding RETURN nodeId, embedding

Procedure names and options vary between GDS versions; check the GDS docs for your version.

An interactive step-by-step visualizer for this algorithm is planned for phase 3.

Profile

Time complexityO(r · l · V) walk generation plus skip-gram training
Space complexityO(V · d)

Relationships

Prerequisite of
Prerequisites
Implemented by