Reputation: 93
I have gensim installed in my system. I did the summarization with gensim. NOw I want to find the similarity between the sentence and it showing an error. sample code is given below. I have downloaded the Google news vectors.
from gensim.models import KeyedVectors
#two sample sentences
s1 = 'the first sentence'
s2 = 'the second text'
#model = gensim.models.KeyedVectors.load_word2vec_format('../GoogleNews-vectors-negative300.bin', binary=True)
model = gensim.models.KeyedVectors.load_word2vec_format('./data/GoogleNews-vectors-negative300.bin.gz', binary=True)
#calculate distance between two sentences using WMD algorithm
distance = model.wmdistance(s1, s2)
print ('distance = %.3f' % distance)
Error#################################################
****Traceback (most recent call last): File "/home/abhi/Desktop/CHiir/CLustering & summarization/.idea/FInal_version/sentence_embedding.py", line 7, in model = gensim.models.KeyedVectors.load_word2vec_format('./data/GoogleNews-vectors-negative300.bin.gz', binary=True) NameError: name 'gensim' is not defined****
Upvotes: 1
Views: 4239
Reputation: 993
Importing with from x import y
only lets you use y
, but not x
.
You can either do import gensim
instead of from gensim.models import KeyedVectors
, or you can directly use the imported KeyedVectors
:
model = KeyedVectors.load_word2vec_format('./data/GoogleNews-vectors-negative300.bin.gz', binary=True)
Upvotes: 1