Skip to content

Commit

Permalink
Replace numpy.random.RandomState with SFC64 - for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
zygm0nt committed Jun 29, 2020
1 parent a74f8e3 commit 1ef5b06
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,8 @@ def prepare_weights(self, hs, negative, wv, update=False, vocabulary=None):
def seeded_vector(self, seed_string, vector_size):
"""Get a random vector (but deterministic by seed_string)."""
# Note: built-in hash() may vary by Python version or even (in Py3.x) per launch
once = random.RandomState(self.hashfxn(seed_string) & 0xffffffff)
return (once.rand(vector_size) - 0.5) / vector_size
once = random.Generator(random.SFC64(self.hashfxn(seed_string) & 0xffffffff))
return (once.random(vector_size) - 0.5) / vector_size

def reset_weights(self, hs, negative, wv):
"""Reset all projection weights to an initial (untrained) state, but keep the existing vocabulary."""
Expand Down

0 comments on commit 1ef5b06

Please sign in to comment.