Expand description
Node2Vec — graph node embeddings via biased random walks and skip-gram.
Node2Vec (Grover & Leskovec, 2016) learns a continuous vector representation for
every node in an undirected graph. It generalises DeepWalk by introducing two
hyperparameters (p and q) that bias the random walk to explore either the
local neighbourhood (BFS-like) or the wider graph (DFS-like), letting the
embedding capture both structural equivalence and community membership.
The algorithm has two phases:
-
Biased random walks — for each node, generate
num_walkswalks of lengthwalk_length. At each step the transition probability is weighted by1/p(return to previous),1.0(common neighbour), or1/q(exploration), and sampled in O(1) with the alias method. -
Skip-gram with negative sampling — treats each walk as a sentence, pairs each node with its context window, and optimises embeddings with SGD. Negative nodes are drawn proportional to
degree^(3/4).
§Features
- Pure Rust — no unsafe code, no dependencies beyond the library itself
- Deterministic output via
random_seed - Supports isolated nodes (walk length 1; embedding is random-initialised)
- p=1, q=1 reproduces standard DeepWalk behaviour
- Fluent builder API matching the rest of the
rune-*family
§Quick Start
use rune_node2vec::Node2Vec;
// A triangle: nodes 0-1-2-0
let edges = vec![(0, 1), (1, 2), (2, 0)];
let result = Node2Vec::new()
.embedding_dim(8)
.n_epochs(5)
.fit(3, &edges);
assert_eq!(result.embeddings.len(), 3);
assert_eq!(result.embeddings[0].len(), 8);§CLI
rune-node2vec graph.edgelist --dim 64 --epochs 5
cat graph.edgelist | rune-node2vec -Structs§
- Embed
Result - The output of a completed Node2Vec run.
- Node2
Vec - Builder for configuring and running the Node2Vec algorithm.