TL;DR
DeepWalk turns each node of a network into a short list of numbers, so that nodes in the same community get similar lists. It does this by sampling many short random walks over the graph and treating each walk as a sentence. A word-embedding model trained on those sentences then places each node in a space of 128 dimensions. The learned vectors work with a simple linear classifier, and they stay useful when most nodes have no labels.
Builds on: Graph, Random Walk, Skip-Gram Model · Leads to: Node Embedding, and the many later methods that replace the walk generator or the training objective
Why it mattered
Earlier network features were hand-built, such as degree counts, or came from spectral methods (see History below). DeepWalk showed that a generic language model could learn node features from walks alone. The features were cheap to compute, could be updated as the graph changed, and were good enough to beat stronger baselines when labels were scarce.
The idea spread quickly. Later methods such as node2vec keep the walk-then-train pipeline and change how the walks are biased. Graph embedding became a standard first step for tasks like recommendation on social platforms and classification of users in large networks. The paper also made the link explicit that structure in a graph and structure in language share a power-law frequency pattern, which the rest of the field has used since.
History
Before 2014, learning features for networks had mostly meant either building them by hand or using spectral methods that factor the adjacency matrix. Both were expensive or inflexible on large, changing graphs. Language modelling had seen a sequence of advances, notably word vectors learned by skip-gram models, which had shown that a simple objective could give useful representations at scale.
Perozzi, Al-Rfou and Skiena noticed that the frequency of vertices in short random walks follows a power law, as word frequencies do. They used that observation to carry the word-vector method over to graphs. The paper appeared in 2014. It caught on because it was simple to implement, fast, and strong on the multi-label classification benchmarks the community already used.
The problem
Start with a graph , where is the set of members and the set of links between them. Some members carry labels, such as the interest groups a user belongs to. The usual approach to predicting labels from a graph is relational classification: each node's label depends on its neighbours' labels, and inference runs iteratively over the whole network. That approach is slow, and errors can cascade from one step to the next.
The paper asks for something different. It wants a matrix with one row per node and only a few columns , learned from the graph structure alone, without looking at the labels. Once learned, the same matrix can be used for many different labelling tasks. The authors list four properties they want: the representation should adapt when the network changes, it should reflect community structure so that nearby vectors mean similar people, it should be low-dimensional so that it generalises when labels are scarce, and it should be continuous, so that decision boundaries are smooth.
How it works
We trace a tiny graph by hand. The graph is a path of four nodes, . Use a window size and walks of length .
- Start a walk at a random node. Pick as the root. A walk moves to a uniformly random neighbour at each step. Check: has one neighbour, , so the first step must go to .
- Continue the walk. From the neighbours are and , and say the walk picks . Then from the neighbours are and , and say it picks . The walk is , which has length 4 as required.
- Treat the walk as a sentence. The vertices are the vocabulary, and the walk is a sentence of four words. Nothing about the nodes' identities is used beyond which vertex each position holds.
- Slide a window over the walk. With , each position is paired with the vertex one step to its left and one step to its right when they exist. This gives the pairs (centre, context): , , , , , . Check: the two interior nodes and give two pairs each, and the two ends and give one each, so .
- Update the vector of the centre node. For each pair, the algorithm adjusts the centre node's vector so that the context node becomes more likely. In the paper this is one stochastic gradient step on .
- Repeat over many walks. The paper starts walks from every node, with in the main experiments. Each pass goes over the nodes in a random order, which the authors note speeds convergence.
- Read off the result. After training, row of is the vector for node . Nodes and , which share many walks, tend to end up with similar vectors.
The model uses dimensions, window , and walks of length in the main setup. Those are the paper's values, and the path example uses far smaller numbers only so you can check every step.
flowchart LR
G[Graph G] --> W[Sample gamma random walks per node, length t]
W --> S[Slide window of size w over each walk]
S --> P[Pairs of centre and context vertices]
P --> SG[SkipGram update of Phi, hierarchical softmax]
SG --> PHI[Matrix Phi: one d-dimensional vector per node]
The math
Let hold one vector per node. For a walk and window size , DeepWalk minimises the sum, over all centre positions in the walk, of the negative log probability of the context vertices within steps of : for each context vertex .
Step 2 in symbols: the walk and the window
The walk is a sequence of vertices , where each is a uniformly chosen neighbour of . In symbols, if is the set of neighbours of , then for . The window around position is the set of positions to , other than itself, clipped to the walk's ends.
The number of (centre, context) pairs a walk produces is the sum, over positions , of the number of positions inside the window. On the four-node example with , that is , as in step 4.
Step 3 in symbols: the pair likelihood
The paper replaces the joint probability of a sequence by a product over a context set, using the relaxation from language modelling in which one word predicts its context without order. For a centre vertex and context vertex , the model needs . Computing this exactly needs a normalising sum over all vertices, which is too costly for graphs with millions of nodes.
Step 4 in symbols: hierarchical softmax
Assign each vertex to a leaf of a binary tree. The path from the root to a leaf is a sequence of tree nodes , with the root and , where . Then
Each internal tree node has its own parameter vector . The factor for the step from a parent node to a child is a logistic classifier. If is the logistic function, the probability of going left at a node is , and of going right is . Each factor is a logistic model, so the cost of one pair falls from a sum over vertices to factors.
Step 5 in symbols: the update
The paper trains with stochastic gradient descent. For one pair with loss , the update is
where is the learning rate. Here is the gradient with respect to the centre vector only, and the tree parameters are updated in the same pass. Because each update touches only a few vectors, parallel workers rarely conflict, which the paper uses to train without locks.
Step 6 in symbols: the walk budget
Each vertex starts walks of length , and each walk with window produces the number of pairs given in step 2. For a walk of length and window , the count is
For the main setting this gives the pair count used in the worked examples below.
Worked examples
Graph , walk , window .
- Position 1 () has one neighbour inside the window, . That gives the pair .
- Position 2 () has two, and . That gives and .
- Position 3 () has two, and . That gives and .
- Position 4 () has one, . That gives .
- Total: pairs.
- Check with the formula of step 6: positions give on the left, sum , and on the right, sum . Total .
Interpretation: nodes and are each centres of two pairs and so receive the most updates. This is one reason they tend to end up closer to each other than is to .
Use , , .
- Count pairs in one walk with step 6. For each position from 1 to 40, the left count is . The values of run from to . The values to sum to , and the remaining positions each contribute , which is .
- So the left total is .
- By symmetry the right total is also , since runs over the same values.
- One walk therefore gives pairs.
- Each vertex starts walks, so each vertex is the root of pairs. Those pairs are spread over the whole walk, so most of them update other vertices as well.
- Check: and .
Interpretation: a single vertex's walks produce tens of thousands of training pairs, so even a sparse node sees many updates. The paper's own sensitivity experiments found that most of the benefit comes once about 30 walks per node are used.
BlogCatalog has vertices and labels. Use the same walk settings as example 2.
- Walks: walks in total.
- Pairs: each walk gives pairs, so pairs in total.
- Compute: , which is about updates to the centre vectors.
- Each update does work with hierarchical softmax, here tree factors.
- Result: about updates of size , which is manageable on one machine with several threads.
- The paper's parallel experiments show that the speed-up on BlogCatalog stays consistent up to 8 workers, with no loss of predictive performance relative to serial training.
Interpretation: the cost grows with the number of walks and the window, not with a dense matrix over the graph. This is why the authors can run the method on YouTube, with over a million vertices, where some baselines cannot run.
Try it: a walk of length with window . How many pairs does it give? Answer: for gives , sum ; gives , sum ; total .
Results
The experiments are multi-label classification on three social networks: BlogCatalog with 10,312 vertices and 39 labels, Flickr with 80,513 vertices and 195 labels, and YouTube with 1,138,499 vertices and 47 labels. The protocol follows earlier papers: a random portion of the labelled nodes is used for training, the rest for testing, the split is repeated 10 times, and a one-vs-rest logistic regression is trained on the vectors. Results are reported as Macro-F1 and Micro-F1.
- Sparse labels. The abstract reports F1 scores up to 10% higher than competing methods when labelled data is sparse, and that DeepWalk can match or beat baselines while using 60% less training data in some experiments.
- BlogCatalog. With 20% of nodes labelled, DeepWalk beats EdgeCluster, Modularity and wvRN even when they are given 90% of the data. SpectralClustering is more competitive, but DeepWalk still wins on Macro-F1 when and on Micro-F1 when .
- Flickr. DeepWalk beats all baselines by at least 3% on Micro-F1. With only 3% of the graph labelled it beats the other methods trained on 10%.
- YouTube. At 1% labelled nodes, Micro-F1 improves by 14% over EdgeCluster, the scalable baseline. The lead narrows as labels grow, and ends at 3% on Micro-F1 and 5% on Macro-F1.
- Parallelism. The speed-up on BlogCatalog and Flickr stays consistent up to 8 workers, with no loss of predictive performance relative to the serial run.
The limits are worth stating. The experiments use one machine with several threads, not a cluster. The paper compares with baselines from the years before its publication, and the claim of superiority is about those baselines and these datasets. The best dimensionality depends on how many labelled examples are available, so is not a universal setting.
Common mistakes and tradeoffs
It is tempting to think that DeepWalk reads the labels to learn its features. In fact the representation is learned from the graph alone. The labels are used only later, by a classifier trained on the vectors, which is why the same vectors can serve many tasks.
It is tempting to think that the walks must be long to capture community structure. In fact the paper uses short walks, , and a window of . Short local walks are enough, and they keep the sampling cheap and easy to parallelise.
It is tempting to think that random walks give the same information as the adjacency matrix. In fact each walk is a sample: it sees the local neighbourhood of its root, and the vectors are built from many such samples rather than from the full matrix. Some global detail is therefore only captured indirectly.
It is tempting to think that the method is a neural network in the usual sense. In fact there is no hidden layer; it is a skip-gram model over vertices with a tree of logistic classifiers. The "deep" in the name refers to unsupervised feature learning in the broad sense.
When to use it: when the graph is large, when labels are sparse, and when the features must be reused for several tasks. When not to: when the graph is small enough for spectral methods and labels are dense, or when edge attributes and directions matter a great deal. Alternatives include spectral embeddings, which give exact eigenvectors at a higher cost, and biased-walk variants such as node2vec.
Reading guide
- Section 1, Introduction. The aim is social representations for sparse networks. It needs Graph and the idea of supervised learning.
- Section 2, Problem Definition. The matrix and relational classification. It needs Graph and Logistic Regression for the later classifier.
- Section 3.1, Random Walks. Walks as a stream of local samples. It needs Random Walk.
- Section 3.2, Power laws. The frequency of vertices in walks follows the same heavy tail as words. It needs the idea of a Power Law and is best read alongside Word Embedding.
- Section 3.3, Language modelling. The move from predicting a word from its history to predicting context without order. It needs Word Embedding and Efficient Estimation of Word Representations in Vector Space (word2vec).
- Section 4.2, Algorithm. Walks, SkipGram and hierarchical softmax. It needs Skip-Gram Model, Hierarchical Softmax, Softmax and Stochastic Gradient Descent.
- Section 4.3, Parallelisability. Asynchronous stochastic gradient descent. It needs Stochastic Gradient Descent.
- Section 6, Experiments. Classification with logistic regression and F1 scores. It needs Logistic Regression.
- Section 7, Related Work. Other ways of creating social dimensions and relational learners. It needs Node Embedding.
Check yourself
QuestionIn the four-node path with window , how many (centre, context) pairs does the walk produce?Show answer
Six. Position gives one pair, and give two each, and gives one. The total is .
QuestionWith and , how many pairs does one walk produce?Show answer
Each side of the window sums to : the first ten positions give , and the other thirty give each, for . The total is .
QuestionWhy does DeepWalk use hierarchical softmax instead of a full softmax over all vertices?Show answer
A full softmax needs a normalising sum over all vertices for every pair, which is too expensive for graphs with millions of nodes. Hierarchical softmax assigns each vertex to a leaf of a binary tree, so one probability is a product of logistic factors, which is much cheaper.
QuestionA researcher says that DeepWalk uses the labels to learn its vectors and so would not generalise to a new labelling task. What is wrong with this?Show answer
The vectors are learned from the walks on the graph alone, without labels. Labels enter only in the classifier trained afterwards. So the same vectors can be reused for a new labelling task by training a new classifier, which is one of the design goals the paper states.
QuestionIn the paper's experiments, what does the sparse-label result mean in practice?Show answer
It means that DeepWalk's vectors, with a simple classifier, can reach the accuracy of baselines that are given far more labelled nodes, such as 20% labelled for DeepWalk against 90% for the baselines on BlogCatalog. Useful structure is learned without labels, so fewer labels are needed for a good classifier.