Skip to content

Instantly share code, notes, and snippets.

@sudodo
Created September 23, 2016 03:09
Show Gist options
  • Select an option

  • Save sudodo/099868f1055b15e9563aca9a290a7fb3 to your computer and use it in GitHub Desktop.

Select an option

Save sudodo/099868f1055b15e9563aca9a290a7fb3 to your computer and use it in GitHub Desktop.
Python parallel processing sample
def map_f(w, model):
return model.get_vector(w)
def get_vector_matrix_for_w2v_model(model, vocab=None):
"""Create vector matrix for word2vec model"""
if vocab is None:
vocab = model.vocab
# vect_mat = np.array([model.get_vector(w) for w in vocab])
p = Pool(multiprocessing.cpu_count() - 1)
partial_map_f = partial(map_f, model=model)
vect_mat = p.map(partial_map_f, vocab)
return vocab, vect_mat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment