sense2vec icon indicating copy to clipboard operation
sense2vec copied to clipboard

ImportError: cannot import name 'cosine_similarity' from 'sense2vec.util'

Open Z-e-e opened this issue 5 years ago • 11 comments

@svlandeg I installed sense2vec through pip I have v 1.0.2 and I get this error: ImportError: cannot import name 'cosine_similarity' from 'sense2vec.util' (/.conda/envs/NewEnv15/lib/python3.7/site-packages/sense2vec/util.py)

Please let me know what I am doing wrong.

Z-e-e avatar Apr 23 '20 21:04 Z-e-e

What exactly are you doing when you get that error? Can you post the original command and the entire stacktrace?

svlandeg avatar Apr 24 '20 08:04 svlandeg

@svlandeg

05_export step:

from collections import OrderedDict, defaultdict from sense2vec import Sense2Vec from sense2vec.util import split_key from sense2vec.util import cosine_similarity from pathlib import Path import plac from wasabi import msg import numpy

Error:

ImportError Traceback (most recent call last) in 2 from sense2vec import Sense2Vec 3 from sense2vec.util import split_key ----> 4 from sense2vec.util import cosine_similarity 5 from pathlib import Path 6 import plac

ImportError: cannot import name 'cosine_similarity' from 'sense2vec.util' (/.conda/envs/NewEnv15/lib/python3.7/site-packages/sense2vec/util.py)

Z-e-e avatar Apr 24 '20 16:04 Z-e-e

I'm a little puzzled by that, because you can import other functions from the same package sense2vec.util (the line above imports split_key), and I just ran the scripts today and didn't run into any trouble ...

svlandeg avatar Apr 24 '20 22:04 svlandeg

@svlandeg I am quite puzzled myself. Like I mentioned earlier, I used pip to install v 1.0.2. I would like to add that I used Jupyter Hub to run this script. Not sure if that is relevant.

Z-e-e avatar Apr 24 '20 22:04 Z-e-e

Does any one resolved this issue?

I am facing this same issue as above

SarangShaikh201 avatar May 06 '20 08:05 SarangShaikh201

Any update on this error?

SarangShaikh201 avatar May 11 '20 06:05 SarangShaikh201

@SarangShaikh201 you probably installed sense2vec via pip, can you try to build & install from master branch?

hakangs avatar May 12 '20 08:05 hakangs

I had the same issue (#110 ). The fix was using the git version of sense2vec rather than the pip version of the package.

santoshbs avatar Jun 03 '20 21:06 santoshbs

Thanks for posting the work around @hakangs and @santoshbs! That also explains why I didn't run into trouble because I built from source.

Still need to investigate what goes wrong when installing with pip though.

svlandeg avatar Jun 04 '20 08:06 svlandeg

Same problem here

i-Hun avatar Jun 25 '20 19:06 i-Hun

Same problem here. Trying to run 05_export.py I face the message: "ImportError: cannot import name 'cosine_similarity' from 'sense2vec.util'"

maxpbn avatar Feb 02 '21 09:02 maxpbn