- Year
- 2014 (DeepWalk); 2016 (Node2Vec)
- Type
- Representation learning / unsupervised network method
What does it do?
Network embedding is a family of representation-learning methods that map each node of a graph to a dense, low-dimensional vector intended to reflect its position and neighbourhood in the network.
DeepWalk, introduced by Perozzi, Al-Rfou, and Skiena in 2014, adapted the skip-gram model from word embeddings to sequences of nodes produced by random walks on a graph. Grover and Leskovec's Node2Vec (2016) extended this with a biased random walk, controlled by the parameters p and q, that balances breadth-first and depth-first neighbourhood exploration. The resulting vectors can serve as inputs to standard machine-learning classifiers and clustering algorithms.
The intuition behind the method
A graph is made of nodes and edges, but most machine-learning algorithms expect a table of numbers. Network embedding addresses this translation problem. Word2Vec learns word meanings from which words appear near one another in sentences; DeepWalk applies the same idea to random walks across a graph, learning node representations from which nodes appear near one another along those walks. The result is a coordinate in a vector space, in which nodes that are structurally similar or frequently visited together tend to lie close together. Once every node has a vector, those vectors can be passed to a classifier or clustered with an algorithm such as k-means, without writing graph-specific model code.
History
Perozzi, Al-Rfou, and Skiena introduced DeepWalk at KDD 2014, generalising the sequence-based learning of language models from sequences of words to walks on a graph. Grover and Leskovec's Node2Vec (KDD 2016) added a biased second-order random walk controlled by p and q, which gives explicit control over how walks explore a neighbourhood.
When to use it
Network embedding is appropriate when your data are a graph, whether weighted or unweighted and directed or undirected, and you need continuous vector features for downstream tasks such as node classification, link prediction, or node clustering. As a practical rule of thumb, graphs with at least about 50 nodes are a reasonable starting point; this is a rough guideline rather than a hard threshold, because very small graphs provide little walk data from which to learn. Choose DeepWalk when uniform random walks are a sufficient starting point. Choose Node2Vec when you want to set the balance between local and outward exploration through p and q, and validate that choice on your task. Do not use the standard form of these methods if new nodes must be embedded at inference time without retraining, since they are transductive; an inductive graph neural network method is the better fit in that case.
Limitations and considerations
- Transductive: nodes absent from the training graph have no vector and cannot be embedded without retraining.
- Hyperparameter sensitivity: embedding dimension, walk length, number of walks, context window size, p, and q all affect embedding quality and should be validated on the downstream task.
- Walks are built from pairwise edges, so higher-order structure such as hyperedges is not represented by the basic form, and multi-relational edge types are not distinguished unless the method is extended. Extended variants for these cases exist.
- On very small graphs the walk corpus may be too sparse to learn reliable representations, which is why the minimum-sample guideline should be taken seriously.
Source conditions do not replace independent scientific review or validation by an analysis engine.
Strengths
- Converts relational graph data into fixed-length vectors that can be used with standard classifiers and clustering algorithms.
- In Node2Vec, p and q set how walks trade off local neighbourhoods against more distant exploration, so the same framework can be tuned toward homophily or toward structural-role similarity.
- Edge weights enter the walk probabilities directly, so relationship strength influences the embedding without a separate modelling step.
- Neighbourhoods are explored by sampling walks rather than enumerating them, which the Node2Vec paper presents as the basis of its efficient exploration of diverse neighbourhoods.
Applications
- Node classification in citation networks, social platforms, or biological interaction graphs.
- Link prediction — identifying missing or future edges by comparing node embedding similarity.
- Community detection by clustering node vectors with k-means or hierarchical methods.
- Anomaly detection — nodes whose embeddings are outliers in the vector space may represent unusual structural roles.
- Recommendation systems where users and items are nodes in a bipartite or multiplex interaction graph.
How it works
How it works
The process begins with a graph G in which nodes are entities and edges represent relationships. Edges may be directed or undirected, and they may carry weights that influence how likely each edge is to be traversed; if no weights are given, all edges are treated as equal. The analyst also chooses the variant: DeepWalk uses uniform random walks, and Node2Vec uses walks biased by p and q. For Node2Vec, the choice of p and q should reflect the pattern expected in the data. In the common reading of the Node2Vec framework, q below 1, which lets walks move outward through the network, supports homophily, where connected nodes tend to be similar, while q above 1, which keeps walks near their starting node, supports structural equivalence, where nodes with similar roles may be far apart. Setting p and q both to 1 gives uniform walks equivalent to DeepWalk.
From each node, the algorithm simulates a set of random walks of fixed length, and each walk produces a sequence of node identifiers that plays the role of a sentence. In DeepWalk, the next node is chosen uniformly among the current node's neighbours. In Node2Vec, each candidate next node receives an unnormalised weight that depends on its relation to the previous node: returning to the previous node has weight 1/p, a node that is also a neighbour of the previous node has weight 1, and a node two steps from the previous node has weight 1/q. A small p therefore makes backtracking more likely, and a small q makes outward moves more likely. Edge weights multiply these factors. The collection of walks forms a corpus of node sequences that encodes the graph's topology.
The corpus of node sequences is fed into a skip-gram model, the architecture used in Word2Vec. For each node in a walk, the model is trained to predict the nodes appearing around it within a context window, using stochastic gradient descent. Because normalising the prediction over every node in the graph is expensive, practical implementations approximate it, most often with negative sampling, in which observed co-occurrences are contrasted with a small number of randomly drawn nodes. Nodes that co-occur in walks thereby acquire similar vectors. The embedding dimension is a hyperparameter; 64 and 128 are common choices in practice. Larger dimensions can capture more structure but cost more computation and can overfit on small graphs.
Once trained, the model provides one embedding vector per node. These vectors can be used as features for node classification (for example, in a logistic regression or a neural classifier), for link prediction by comparing the vectors of candidate node pairs, or for community detection by clustering the vectors. The embeddings are transductive: they cover only the nodes seen during training. If new nodes must be embedded after training, an inductive graph neural network method is the appropriate alternative, because standard Node2Vec and DeepWalk models have no vector for unseen nodes without retraining.
Common pitfalls
- Applying a trained Node2Vec or DeepWalk model to nodes that were not in the training graph; the model has no vector for them, so an inductive graph neural network method is needed when this must be supported.
- Leaving p and q at 1 (which makes walks uniform, as in DeepWalk) without considering whether the network is expected to show homophily or structural equivalence.
- Reading the direction of q backwards: q below 1 favours outward moves and q above 1 keeps walks near their start, so a reversed reading produces embeddings that encode the opposite pattern.
- Treating the embedding dimension as a fixed constant; on small graphs a dimension of 64 or 128 may overfit, so the dimension should be checked against downstream performance.
- Expecting reliable embeddings from very small graphs, where the walk corpus provides little signal.
Frequently asked questions
What is the difference between DeepWalk and Node2Vec?
DeepWalk uses uniform random walks and the Word2Vec-style skip-gram model, and it is the simpler of the two. Node2Vec uses the same training approach but biases each walk step with p and q, so the analyst can tune whether walks stay local or move outward.
How do I choose the p and q parameters in Node2Vec?
The return parameter p sets the weight 1/p for stepping back to the previous node, so a small p makes backtracking more likely. The in-out parameter q sets the weight 1/q for moving to a node two steps from the previous node, so a small q (below 1) favours outward exploration and a large q (above 1) keeps the walk near its starting point. If you expect similar nodes to cluster together (homophily), try q below 1. If you expect nodes with similar structural roles to be similar even when far apart, try q above 1. Validate the chosen settings on your downstream task.
Can I embed new nodes after training without retraining the whole model?
Standard Node2Vec and DeepWalk are transductive: the embedding matrix covers only the nodes seen during training. For new, previously unseen nodes, an inductive graph neural network method is the appropriate choice, because such methods learn a function that computes a node's representation from its neighbourhood, so they can be applied at inference time to nodes that were not present during training.
How many dimensions should I use for the embedding?
64 and 128 are common choices in practice. For small graphs, starting with a lower dimension is a reasonable way to limit overfitting, and the choice should be judged by performance on the downstream task rather than by reconstruction error alone.
Related methods
Sources
Grover, A. & Leskovec, J. (2016). Node2Vec: Scalable Feature Learning for Networks. Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD), 855-864.
Open DOI referencePerozzi, B., Al-Rfou, R., & Skiena, S. (2014). DeepWalk: Online Learning of Social Representations. Proceedings of the 20th ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD), 701-710.
Open DOI reference