AI Glossary / Deep learning / Intermediate
node2vec
Definition
node2vec is a graph representation method that learns a numerical vector for each node by predicting neighborhood relationships sampled through biased random walks. These vectors can become features for tasks such as node classification or link prediction.
What it means
A graph records entities and their connections: products bought together, papers citing one another or components linked in an assembly. A conventional prediction model may need a fixed list of numbers for each entity. node2vec learns that list from patterns in the connections.
The method was introduced by Aditya Grover and Jure Leskovec in 2016. Its neighborhood is flexible: the sampling procedure can favor returning, exploring nearby connections or moving farther from the previous location. Consequently, the learned representation depends on how the graph is explored.
An embedding is a representation, not a final business decision. Another model or scoring rule must turn it into a recommendation or prediction. Although grouped here with deep learning, the original method uses a shallow node embedding rather than requiring a deep graph neural network.
How it works
First define the graph, including what edges and their weights mean. Generate sequences of visited nodes using random walks. The next step depends on the current node and the preceding node, making the walk second order.
Two positive parameters control relative transition weights. The return parameter p affects immediate backtracking. The in-out parameter q affects moves farther from the preceding node. These weights are normalized into probabilities; they are not independent probabilities themselves.
A neighborhood prediction objective then learns vectors from node co-occurrences in the sampled sequences, borrowing the general approach of word-context representation learning. Walk length, context window and embedding dimension also influence the result.
The original lookup-based representation assigns vectors to nodes in the training graph. It does not automatically supply an embedding for an entirely new node from its attributes. Changes to graph membership therefore need an explicit update or alternative modeling strategy.
Three practical examples
- A catalog analyst uses product co-purchase connections to create candidate recommendations, then checks relevance and availability separately.
- A research team studies protein interaction networks and evaluates whether graph-derived features help a carefully held-out classification task.
- A digital library explores citation-based paper relationships, distinguishing structural similarity from similarity of the papers' actual text.
Think of it this way
Think of learning about a town by repeatedly taking short walks through its street network. Walks that frequently retrace their steps reveal a different picture from walks that tend to move onward. A notebook of frequently encountered places can summarize the experience.
The analogy concerns sampling relationships. node2vec has no understanding of a town, and two nearby vectors need not describe entities with the same purpose, quality or causal relationship.
Worked example
Turning walk preferences into probabilities
In an invented unweighted, undirected graph, a walker arrives at V from T. V has three neighbors: T itself, A, which is also connected to T, and B, which is not directly connected to T. Choose p = 2 and q = 0.5.
The relative weights for the next step are 1/p = 0.5 for returning to T, 1 for moving to A, and 1/q = 2 for moving to B. Their sum is 3.5. The resulting probabilities are therefore 1/7, 2/7 and 4/7 respectively.
B is favored, but not guaranteed. These are transition probabilities for this particular graph position, not probabilities that B is a relevant recommendation. With p = q = 1, the three equally weighted edges would each receive probability 1/3. Learning embeddings requires many sampled contexts beyond this single step.
Illustrative case study
Fictional example: Larch Books builds a graph connecting titles purchased together and uses node2vec features to rank possible future pairings. Its first evaluation looks unusually strong.
A reviewer discovers that the graph includes purchases made during the evaluation period. Even though the embedding procedure did not use the prediction labels directly, it could see connections that would not have existed when the recommendations were needed.
The team rebuilds each evaluation graph using only information available before its cutoff. It compares the resulting recommendations with a simple popularity baseline and examines less frequently purchased titles separately. It also keeps a fallback for newly introduced books that lack learned vectors.
The lesson is that an unsupervised representation can still leak future information. A credible assessment must respect when the underlying relationships become available.
Common misconceptions and mistakes
- Unsupervised training prevents leakage. Future edges or other unavailable graph information can still contaminate an evaluation.
- Similar embeddings prove similar meaning. They reflect the sampled connectivity objective; textual or functional meaning requires separate evidence.
- One parameter setting is universally best. Useful walk behavior depends on graph structure and the downstream task.
- Every new node is immediately supported. The original node lookup needs an explicit strategy for unseen entities.
Business use
node2vec can be useful when relationships contain predictive information that ordinary entity attributes miss. Before investing, specify the action the representation will support and compare it with simple graph statistics and non-graph baselines.
Operational costs include graph construction, walk generation, embedding refreshes and handling new or isolated nodes. Track performance by node popularity and by time period. A single average score can hide weak coverage of the very items the business wants to introduce or promote.
People also ask
Is node2vec the same as word2vec?
No. It applies a related neighborhood-prediction idea to graph-derived node sequences rather than ordinary word sequences.
Does it predict links by itself?
It produces representations that can support a link-scoring method; the prediction setup and evaluation still need definition.
Do the vector coordinates have named meanings?
Generally no. An individual coordinate should not automatically be labeled as a business characteristic.
Check your understanding
A recommendation experiment removes test labels but lets node2vec walk over purchases recorded after the prediction date. Is that a clean future-prediction test?
Answer: No. The graph itself contains future information. Rebuild the representation from the information available at the prediction cutoff.
Related terms
- Random walk
- Representation learning
- Graph neural network
- Graph embedding
- word2vec
- link prediction
- transductive learning
Learn next
Read graph embedding and data leakage. Draw a small relationship graph, define exactly when an edge becomes available, and calculate one normalized walk transition before considering a prediction model.
More in Deep learning
- Neural style transfer - Neural style transfer is a family of image-transformation methods that uses neural representations to combine aspects of one image's content with aspects of...
- Neural Turing Machine Network - A Neural Turing Machine, or NTM, is a neural architecture that combines a trainable controller with an external memory matrix.
- Neuro-fuzzy systems - Neuro-fuzzy systems combine neural or adaptive learning methods with fuzzy inference.
- Oja's rule - Oja's rule is an unsupervised learning rule for a linear neuron that combines Hebbian reinforcement with an activity-dependent stabilizing term.
- Optical neural network - An optical neural network performs some or all of its neural computation using light and optical components.
- Oscillatory neural network - An oscillatory neural network is a computational network whose units have oscillating states and whose interactions are used to process information.
Sources
Grover and Leskovec, node2vec: Scalable Feature Learning for Networks: https://arxiv.org/abs/1607.00653. Authors' project and walk overview: https://snap.stanford.edu/node2vec/. Stanford course material on node representations: https://snap-stanford.github.io/cs224w-notes/machine-learning-with-networks/node-representation-learning. Numerical and business examples are original illustrations.
Previous: Node degree Next: Noise