Skip to content

Instantly share code, notes, and snippets.

@rohithteja
Last active February 19, 2024 16:24
Show Gist options
  • Save rohithteja/58a4ee25aafd9692f37a15c1bd882e71 to your computer and use it in GitHub Desktop.
Save rohithteja/58a4ee25aafd9692f37a15c1bd882e71 to your computer and use it in GitHub Desktop.
DeepWalk embeddings on Karate Club dataset
from ge import DeepWalk
# load graph from networkx library
G = nx.karate_club_graph()
labels = np.asarray([G.nodes[i]['club'] != 'Mr. Hi' for i in G.nodes]).astype(np.int64)
# convert nodes from int to str format
keys = np.arange(0,34)
values = [str(i) for i in keys]
dic = dict(zip(keys, values))
H = nx.relabel_nodes(G, dic)
# train the model and generate embeddings
model = DeepWalk(H, walk_length=10, num_walks=80, workers=1)
model.train(window_size=5,iter=3)
embeddings = model.get_embeddings()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment