I am running into this error when i import this
from gensim.models import KeyedVectors
the error is
File "c:\Users\frase\eg1.py", line 11, in <module>
from gensim.models import KeyedVectors
File "C:\Users\frase\AppData\Local\Programs\Python\Python39\lib\site-packages\gensim\__init__.py", line 11, in <module>
from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401
File "C:\Users\frase\AppData\Local\Programs\Python\Python39\lib\site-packages\gensim\corpora\__init__.py", line 6, in <module>
from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes
File "C:\Users\frase\AppData\Local\Programs\Python\Python39\lib\site-packages\gensim\corpora\indexedcorpus.py", line 14, in <module>
from gensim import interfaces, utils
File "C:\Users\frase\AppData\Local\Programs\Python\Python39\lib\site-packages\gensim\interfaces.py", line 19, in <module>
from gensim import utils, matutils
File "C:\Users\frase\AppData\Local\Programs\Python\Python39\lib\site-packages\gensim\matutils.py", line 1024, in <module>
from gensim._matutils import logsumexp, mean_absolute_difference, dirichlet_expectation
File "gensim/_matutils.pyx", line 1, in init gensim._matutils
#!/usr/bin/env cython
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
I have used KeyedVectors before to load in a model, but this started to occur when i installed 'TensorFlow'.
I have looked up this issue, and reduced the version of Numpy to 1.19.2 (which is max for Tensorflow), but that did not work. I have also tried to simply uninstall and reinstall and that also has not worked.
Any reason why this is happening?
Example of code used for (NOTE: I can't test it so there might be errors):
model = KeyedVectors.load_word2vec_format(
'\Word2vec\GoogleNews-vectors-negative300.bin.gz', binary=True)
# create the embedding matrix
embedding_matrix = np.zeros((vocab_size, 300)) # 300 is dim size
for word, vector in model.key_to_vectors():
if(word in tokenizer.word_index):
idx = tokenizer.word_index[word]
embedding_matrix[idx] = np.array(vector, dtype=np.float32)