Skip to content

Commit 6ce30fd

Browse files
author
Aditya Grover
committed
comments added
1 parent cd22b84 commit 6ce30fd

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,20 @@ def read_graph():
8080
return G
8181

8282
def learn_embeddings(walks):
83-
83+
'''
84+
Learn embeddings by optimizing the Skipgram objective using SGD.
85+
'''
8486
walks = [map(str, walk) for walk in walks]
8587
model = Word2Vec(walks, size=args.dimensions, window=args.window_size, min_count=0,
8688
workers=args.workers, iter=args.iter)
8789
model.save_word2vec_format(args.output)
90+
8891
return
8992

9093
def main(args):
94+
'''
95+
Pipeline for representational learning for all nodes in a graph.
96+
'''
9197
nx_G = read_graph()
9298
G = node2vec.Graph(nx_G, args.directed, args.p, args.q)
9399
G.preprocess_transition_probs()

src/node2vec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def simulate_walks(self, num_walks, walk_length):
9595
random.shuffle(nodes)
9696
for node in nodes:
9797
walks.append(self.node2vec_walk(walk_length=walk_length, start_node=node))
98+
9899
return walks
99100

100101
def get_alias_edge(self, src, dst):
@@ -115,6 +116,7 @@ def get_alias_edge(self, src, dst):
115116
unnormalized_probs.append(G[dst][dst_nbr]['weight']/q)
116117
norm_const = sum(unnormalized_probs)
117118
normalized_probs = [float(u_prob)/norm_const for u_prob in unnormalized_probs]
119+
118120
return alias_setup(normalized_probs)
119121

120122
def preprocess_transition_probs(self):

0 commit comments

Comments
 (0)