Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting an error to install pyemd even though I just installed it

Here is the code:

from pyemd import emd

print("sentence 1:")
print(input_document_lower[0])
print("sentence 2:")
print(input_document_lower[1])
print("similarity:")
model_w2v.wmdistance(input_document_lower[0], input_document_lower[1])

Here's the error:

sentence 1:
incorrect batch number printed primary label pbn
sentence 2:
unconfirmed oos met vial washing qualification sample per 
similarity:

ImportErrorTraceback (most recent call last)
<ipython-input-201-50af089a2354> in <module>()
      4 print(input_document_lower[1])
      5 print("similarity:")
----> 6 model_w2v.wmdistance(input_document_lower[0], input_document_lower[1])

C:\ProgramData\Anaconda2\lib\site-packages\gensim\models\word2vec.pyc in wmdistance(self, document1, document2)
   1308         Refer to the documentation for `gensim.models.KeyedVectors.wmdistance`
   1309         """
-> 1310         return self.wv.wmdistance(document1, document2)
   1311 
   1312     def most_similar_cosmul(self, positive=None, negative=None, topn=10):

C:\ProgramData\Anaconda2\lib\site-packages\gensim\models\keyedvectors.pyc in wmdistance(self, document1, document2)
    386 
    387         if not PYEMD_EXT:
--> 388             raise ImportError("Please install pyemd Python package to compute WMD.")
    389 
    390         # Remove out-of-vocabulary words.

ImportError: Please install pyemd Python package to compute WMD.

It is being installed properly so I really have no clue as to what is going wrong. Have any of your encountered this?

like image 879
madsthaks Avatar asked Nov 03 '17 23:11

madsthaks


1 Answers

I had the same error, and for me the solution was to swap:

from gensim.similarities import WmdSimilarity
from pyemd import emd

into

from pyemd import emd
from gensim.similarities import WmdSimilarity

Don't ask me why it works.

like image 191
wessel Avatar answered Oct 12 '22 23:10

wessel