avidale / compress-fasttext

Tools for shrinking fastText models (in gensim format)
MIT License
165 stars 13 forks source link

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject. #17

Closed shrey6996 closed 1 year ago

shrey6996 commented 1 year ago

I installed using !pip install compress-fasttext in colab and it works fine. But when I try to import it via import compress_fasttext it errors out. I tried upgrading the numpy version, building pycocotools as mentioned in various Stack Overflow links but nothing works.

(ValueError Traceback (most recent call last) in 1 get_ipython().system('pip install compress-fasttext') ----> 2 import compress_fasttext

7 frames /usr/local/lib/python3.8/dist-packages/compress_fasttext/init.py in ----> 1 from compress_fasttext import compress, decomposition, evaluation, navec_like, prune, quantization, utils 2 from compress_fasttext import models 3 from compress_fasttext.compress import make_new_fasttext_model, quantize_ft, svd_ft, prune_ft, prune_ft_freq 4 from compress_fasttext.models import CompressedFastTextKeyedVectors

/usr/local/lib/python3.8/dist-packages/compress_fasttext/compress.py in 3 4 import numpy as np ----> 5 from gensim.models.fasttext import FastTextKeyedVectors 6 7 from .decomposition import DecomposedMatrix

/usr/local/lib/python3.8/dist-packages/gensim/init.py in 9 import logging 10 ---> 11 from gensim import parsing, corpora, matutils, interfaces, models, similarities, utils # noqa:F401 12 13

/usr/local/lib/python3.8/dist-packages/gensim/corpora/init.py in 4 5 # bring corpus classes directly into package namespace, to save some typing ----> 6 from .indexedcorpus import IndexedCorpus # noqa:F401 must appear before the other classes 7 8 from .mmcorpus import MmCorpus # noqa:F401

/usr/local/lib/python3.8/dist-packages/gensim/corpora/indexedcorpus.py in 12 import numpy 13 ---> 14 from gensim import interfaces, utils 15 16 logger = logging.getLogger(name)

/usr/local/lib/python3.8/dist-packages/gensim/interfaces.py in 17 import logging 18 ---> 19 from gensim import utils, matutils 20 21

/usr/local/lib/python3.8/dist-packages/gensim/matutils.py in 1028 try: 1029 # try to load fast, cythonized code if possible -> 1030 from gensim._matutils import logsumexp, mean_absolute_difference, dirichlet_expectation 1031 1032 except ImportError:

/usr/local/lib/python3.8/dist-packages/gensim/_matutils.pyx in init gensim._matutils()

ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject)

avidale commented 1 year ago

Hi @shrey6996 ! For me, just upgrading numpy to the latest version and then restarting the runtime worked fine. Here is a notebook that reproduces it https://colab.research.google.com/drive/1ddqodId2pmpT-qtW0Y93kH0aR2CnqACB?usp=sharing Does it work for you?

shrey6996 commented 1 year ago

@avidale It works sometimes which is wierd! So I tried it on colab by first running the code without upgrading numpy and I got the above mentioned error. So I upgraded it, restarted the runtime and then it wokrs fine.

But if I first upgrade numpy and then run I get the error "AttributeError: module 'numpy' has no attribute '_no_nep50_warning'"

avidale commented 1 year ago

Yes, the same happens for me. But it happens even without compress-fasttext: you can try e.g. just pip install gensim>=4.0.0 and then call from gensim import corpora, and you'll get the same error. This is because the error is generated somewhere between Gensim, Scipy and Numpy, and I, as a developer of compress-fasttext, cannot really help it.