Created
May 25, 2018 09:35
-
-
Save nokados/feeb86d3da41280154ae56a7d9683117 to your computer and use it in GitHub Desktop.
Average word vectors in a text
This file contains 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 calc_embedding(text): | |
tokens = word_tokenize(text) | |
vec = np.zeros(100) | |
num_tokens = 0 | |
for token in tokens: | |
if token in stopwords_list: | |
continue | |
if token in new_model: | |
vec += new_model[token] | |
num_tokens += 1 | |
if num_tokens: | |
return vec/num_tokens | |
else: | |
return np.NAN |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment