ImportError: cannot import name '_l2_norm' from 'gensim.models.keyedvectors
pratikkotian04 opened this issue · comments
ImportError Traceback (most recent call last)
in ()
----> 1 from fse import Vectors, Average, IndexedList
2 vecs = Vectors.from_pretrained("fasttext-wiki-news-subwords-300")
3 model = Average(vecs)
3 frames
/usr/local/lib/python3.7/dist-packages/fse/models/base_s2v.py in ()
40
41 from gensim.models.base_any2vec import BaseWordEmbeddingsModel
---> 42 from gensim.models.keyedvectors import BaseKeyedVectors, FastTextKeyedVectors, _l2_norm
43 from gensim.utils import SaveLoad
44 from gensim.matutils import zeros_aligned
ImportError: cannot import name '_l2_norm' from 'gensim.models.keyedvectors' (/usr/local/lib/python3.7/dist-packages/gensim/models/keyedvectors.py)
Hi, I don't know which version of Gensim you are using but I can tell you that in versions >=4 the _l2_norm
function has been removed from keyedvectors.py
.
You can either choose to
- edit your locally downloaded version of Gensim replacing
_l2_norm
withlinalg.norm
after adding linalg to the numpy import in the file's imports section - update your fse with the porting I just made for Gensim >=4 (which also solves this problem) by executing the command
pip install -U git+https://github.com/AleMuzzi/Fast_Sentence_Embeddings
works both as an upgrade and as a new version, pull request is waiting for approval (#65)
Should be fixed in v1.0.0