Created
September 23, 2016 03:09
-
-
Save sudodo/099868f1055b15e9563aca9a290a7fb3 to your computer and use it in GitHub Desktop.
Python parallel processing sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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