-
Notifications
You must be signed in to change notification settings - Fork 255
Add seed parameter. #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This allows to get the exact same results in one process.
|
If I understand you correctly - do you mean this works only for |
|
Yes. This is also the case for gensim (https://radimrehurek.com/gensim/models/word2vec.html). |
eliorc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please view my comments
|
Hi, please change the target of the request to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two commits fix a uncorrelated typo and add additional explanation about the seed parameter.
The working of the seed parameter can be checked with the following example:
import random
import networkx as nx
from node2vec import Node2Vec
import numpy as np
import pandas as pd
random.seed(0)
np.random.seed(0)
G = nx.karate_club_graph()
def get_embedding():
model = Node2Vec(G, dimensions=4, seed=0)
embedding = model.fit()
return pd.DataFrame(embedding.wv.vectors, index=embedding.wv.index2entity)
print('Embedding 1')
print(get_embedding().sort_index().head())
print('Embedding 2')
print(get_embedding().sort_index().head())
Hi Elior Cohen (and others),
This is my first pull request ever. Please help me a bit when I miss certain things.
A while ago we noticed that this Node2Vec implementation yields different results, even when run in one Python process. This problem is also mentioned by @marcovarrone in Issue #26.
In this pull request, we (@pereirabarataap and me) propose to add a simple parameter
seed, which allows to set the random seed of both Numpy and the Python random module.This issue fixes:
another-example.pyat https://github.com/gerritjandebruin/node2vec/blob/another-example/another-example.py.Future work:
At this moment it does not, also not with a fixed PYTHONHASHSEED.
Kind regards,
Gerrit-Jan and António