Node2Vec
¶
Node2Vec(
edge_index: array,
embedding_dim: int,
walk_length: int,
context_size: int,
num_nodes: int,
walks_per_node: int = 1,
p: float = 1.0,
q: float = 1.0,
num_negative_samples: int = 1,
use_gpu: bool = True,
)
Bases: Module
The Node2Vec model from the
"node2vec: Scalable Feature Learning for Networks" paper where random walks of
length walk_length are sampled in a given graph, and node embeddings
are learned via negative sampling optimization.
Note
Random-walk sampling uses the kernels of mlx_cluster, a
dependency of mlx-graphs on macOS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
The edge indices. |
required | |
embedding_dim
|
The size of each embedding vector. |
required | |
walk_length
|
The walk length. |
required | |
context_size
|
The actual context size which is considered for positive samples. This parameter increases the effective sampling rate by reusing samples across different source nodes. |
required | |
num_nodes
|
Number of nodes in a graph |
required | |
walks_per_node
|
The number of walks to sample for each
node. (default: |
required | |
p
|
Likelihood of immediately revisiting a node in the
walk. (default: |
required | |
q
|
Control parameter to interpolate between
breadth-first strategy and depth-first strategy (default: |
required | |
num_negative_samples
|
int
|
The number of negative samples to
use for each positive sample. (default: |
1
|
Methods:
| Name | Description |
|---|---|
__call__ |
Returns the embeddings for the nodes in |
dataloader |
Dataloader for nodes |
loss |
Computes the loss given positive and negative random walks. |
Source code in mlx_graphs/algorithms/node2vec.py
__call__
¶
dataloader
¶
Dataloader for nodes
Source code in mlx_graphs/algorithms/node2vec.py
loss
¶
Computes the loss given positive and negative random walks.
Source code in mlx_graphs/algorithms/node2vec.py
from mlx_graphs.algorithms import Node2Vec · mlx_graphs/algorithms/node2vec.py