Proofs: DeepWalk
These are the human proofs of DeepWalk, at full length.
DeepWalk is stochastic gradient descent on the skip-gram loss of its walks full
This proof shows: correctness, termination.
Let be a graph with , given by the out-lists , and let be a binary tree whose leaves are the vertices and in which every inner node has two children, so has inner nodes. For a vertex , let be the inner nodes on the path from the root to the leaf of , with for a step to the left child and for a step to the right child. For and vectors , write
with .
Termination. Line L2 runs times and line L4 runs times per pass. A walk has at most vertices, so lines L6 and L7 run at most times per walk, and each tree path has at most nodes. Every loop is over a finite range, so the algorithm stops.
Lemma 1 (walks). Given its start , the sequence of line L5 has the distribution of the simple random walk on from , stopped after vertices or at the first vertex with no out-neighbour. In particular, consecutive vertices of are joined by an arc.
Proof. The walk starts at . While it has fewer than vertices and its last vertex has an out-neighbour, it appends an element of drawn uniformly and independently of the past, which is the transition rule of the simple random walk; otherwise it stops.
Lemma 2 (pairs). For a walk of length , lines L6 and L7 visit each ordered pair of positions with and exactly once, and no other pair.
Proof. Line L6 takes each once. Line L7 takes each in the range once and skips . These are exactly the with and .
Lemma 3 (the model is a distribution). For every and every , for each , and .
Proof. Each factor is positive. For a node of , let be the product of over the inner nodes strictly above on the path from the root, with the sign of the step taken at , so and . We show by induction on the height of that the sum of over the leaves below equals . For a leaf it is clear. For an inner node with children (left) and (right), and , so by induction the sum below is with . Since , this is . At the root, the sum over all leaves is .
Lemma 4 (one update is one gradient step). Fix a pair of line L7, with , and the current . After lines L8 and L9,
and no other vector changes.
Proof. Since , . The inner nodes on are distinct, so each with occurs in exactly one term of , and by the chain rule
while does not depend on the other or on the other rows of .
Line L9 handles the nodes of in turn. When it reaches , the vector has not yet changed during this pair, because the nodes are distinct, and has not changed, because is written only after the loop; the vectors belong to inner nodes and are separate from the rows of , so writing does not touch , even when . So is computed from the values before the pair, and . The accumulator receives with the old , read before the update. After the loop it holds , and adding it to gives the claim.
Theorem. DEEPWALK stops and returns after the following process: it draws random walks as in Lemma 1, from each vertex, and for each walk, in the order of Lemma 2, it takes for each pair of positions one gradient step of size on the loss of the probability distribution of Lemma 3, at the current values of and .
Proof. Termination was shown above. Lines L2 to L4 start one walk at each vertex in each of the passes. By Lemma 1 each walk is a stopped simple random walk, by Lemma 2 the inner loops visit exactly the pairs of positions at most apart, once each, by Lemma 3 the loss of each pair is the negative logarithm of a probability distribution on , and by Lemma 4 each visit performs exactly one gradient step on that loss and changes nothing else. Line L10 returns .
So DeepWalk is stochastic gradient descent, with the samples generated online, on , the sum over all pairs of its walks. The loss is not convex in , so the theorem says nothing about reaching a global minimum.