Last active
November 10, 2017 15:15
-
-
Save angadn/0f45362a646b25a254abf63b70bdf611 to your computer and use it in GitHub Desktop.
Gensim Test
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
""" | |
Tests gensim with the Google News Word2Vec model | |
""" | |
import gensim | |
import numpy | |
from scipy import spatial | |
M = gensim.models.KeyedVectors.load_word2vec_format( | |
"./GoogleNews-vectors-negative300.bin", binary=True | |
) | |
while True: | |
try: | |
vec1 = numpy.zeros(300) | |
for w in raw_input("Word 1: ").split(" "): | |
vec1 = vec1 + M.wv[w] | |
vec2 = numpy.zeros(300) | |
for w in raw_input("Word 2: ").split(" "): | |
vec2 = vec2 + M.wv[w] | |
print(1 - spatial.distance.cosine(vec1, vec2)) | |
except Exception as e: | |
print(e.message) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment