Skip to content

Instantly share code, notes, and snippets.

@yaronv
Last active September 12, 2018 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaronv/20727dfe1a1488d27572272f02248daf to your computer and use it in GitHub Desktop.
Save yaronv/20727dfe1a1488d27572272f02248daf to your computer and use it in GitHub Desktop.
def get_mean_vector(word2vec_model, words):
# remove out-of-vocabulary words
words = [word for word in words if word in word2vec_model.vocab]
if len(words) >= 1:
return np.mean(word2vec_model[words], axis=0)
else:
return []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment