aditya-grover / node2vec

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

Seed functionality #62

Closed ttuygun closed 5 years ago

ttuygun commented 5 years ago

Is there a way to adding seeding functionality in order to produce same result for debugging/testing purposes?

We try to seed before every rand function call but it produces different results in every run.

def simulate_walks(self, num_walks, walk_length):
...
    random.seed(self.random_state)
    random.shuffle(nodes)
...
def alias_draw(J, q, random_state):
...
    np.random.seed(random_state)
    kk = int(np.floor(np.random.rand()*K))
...
    np.random.seed(random_state)
    if np.random.rand() < q[kk]:
...

Is there anything that we missed?

DozenCoder commented 5 years ago

Try to use same random seed?Such as:

random.seed(1)
ttuygun commented 5 years ago

Yes, I have already tried as

ttuygun commented 5 years ago

I've solved the problem. The problem related with the Word2Vec's workers count. Gensim documentation said that we need to set workers=1 in order to generate reproducible run.

Note that for a fully deterministically-reproducible run, you must also limit the model to a single worker thread (workers=1)

maxaalexeeva commented 4 years ago

Hi, @ttuygun! Does 'same result' in case of node2vec mean you get exactly same embeddings for each node? Thank you!

ttuygun commented 4 years ago

Hi, @ttuygun! Does 'same result' in case of node2vec mean you get exactly same embeddings for each node? Thank you!

Yes, exactly

maxaalexeeva commented 4 years ago

@ttuygun, thank you!