aditya-grover / node2vec

http://snap.stanford.edu/node2vec/
MIT License
2.6k stars 912 forks source link

Can node2vec be used in Chinese? A data format similar to my following? #106

Open HJW3536 opened 3 years ago

HJW3536 commented 3 years ago

image Chinese characters represent nodes, and numbers represent weights.Has anyone done a similar experiment? Ask for advice

shoegazerstella commented 3 years ago

My advice is to encode the text with a label encoder like this:

le = LabelEncoder()
le.fit(df.stack().unique())

# save label encoder
np.save('label_encoder.npy', le)

df['source'] = le.transform(df['source'])
df['destination'] = le.transform(df['destination'])

then

le = np.load('label_encoder.npy', allow_pickle=True).tolist()

# get node_id
le.transform([node_name])[0]

# get node name
le.inverse_transform([node_id])[0]