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 23, 2020
1 parent 374de28 commit 32c2095
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gensim/models/word2vec.py
Original file line number Diff line number Diff line change
Expand Up @@ -1691,8 +1691,10 @@ 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 32c2095

Please sign in to comment.