趁着周末,久违的看看之前的 embedding 相关知识。
deepWalk 代码:
def deepwalk_walk(self, walk_length, start_node): | |
walk = [start_node] | |
while len(walk) < walk_length: | |
cur = walk[-1] | |
cur_nbrs = list(self.G.neighbors(cur)) | |
if len(cur_nbrs) > 0: | |
walk.append(random.choice(cur_nbrs)) | |
else: | |
break | |
return walk |