<jupyter_start><jupyter_text>**As it is written in the title, in this notebook we generate embedding for each node by training a Node2Vec model.  Source : [Nodevectors Github](https://github.com/VHRanger/nodevectors)**<jupyter_code>!pip install nodevectors
import networkx as nx
import gzip
import pickle
import os

def save(object, filename, protocol = 0):
        """Saves a compressed object to disk
        """
        file = gzip.GzipFile(filename, 'wb')
        file.write(pickle.dumps(object, protocol))
        file.close()
G = nx.read_edgelist('/content/drive/MyDrive/altegrad_datachallenge/collaboration_network.edgelist', delimiter=' ', nodetype=int)
g2v = Node2Vec(n_components=128, walklen=60, threads=os.cpu_count(), w2vparams={'window': 10, 'negative':5, 'iter': 20, 'batch_words':128})

g2v.fit(G) # It took about 7 hours

emb_per_nodes = {}
for node in tqdm(list(G.nodes())):
    emb_per_nodes[node] = g2v.predict(node)
save(emb_per_nodes, '/content/drive/MyDrive/altegrad_datachallenge/Node2Vec.txt') # Save the node embedding
g2v.save('/content/drive/MyDrive/altegrad_datachallenge/node2vecmodel') # save the node embedding model<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup