MartinoMensio / spacy-universal-sentence-encoder

Google USE (Universal Sentence Encoder) for spaCy
MIT License
176 stars 12 forks source link

Library incompatible with latest versions of spaCy and tensorflow #5

Closed rdjondo closed 4 years ago

rdjondo commented 4 years ago

Hello,

This library looks great but, when I tried installing it on my machine which has the latest version of spaCy (2.3.0) and Tensorflow (2.2).

Unfortunately, I could not get it to work and it seems a number of changes would need to be done to make it compatible.

MartinoMensio commented 4 years ago

Hi @rdjondo, I didn't test it yet on the new spaCy 2.3.0. Did you install it from GitHub (pip install git+https://github.com/MartinoMensio/spacy-universal-sentence-encoder-tfhub.git)? Which specific exceptions do you see?

I'll test it very soon. Martino

rdjondo commented 4 years ago
  1. pip install spacy-universal-sentence-encoder -> pip automatically uninstalls tensorflow 2.2 and installs tensorflow 2.1.0 instead
  2. After the pip installation has completed run:
    import spacy
    nlp = spacy.load('en_use_md')

    This returns the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<timed exec> in <module>
~/anaconda3/lib/python3.7/site-packages/spacy_universal_sentence_encoder/__init__.py in <module>
     19 # warning suppress for empty vocabulary
     20 # (setting on the environ wouldn't work if spacy is already loaded)
---> 21 spacy.errors.SPACY_WARNING_IGNORE.append('W007')
     22 
     23 Language.factories['save_tfhub_model_url'] = lambda nlp, **cfg: SaveTfhubModelUrl(nlp, **cfg)

AttributeError: module 'spacy.errors' has no attribute 'SPACY_WARNING_IGNORE'
  1. Commenting the error line (21) in the spacy_universal_sentence_encoder/init.py does not fix the everything. After commenting it, the code hangs after this warning
anaconda3/lib/python3.7/site-packages/spacy/util.py:271: UserWarning: [W031] Model 'en_use_md' (0.2.2) requires spaCy v2.2 and is incompatible with the current spaCy version (2.3.0). This may lead to unexpected results or runtime errors. To resolve this, download a newer compatible model or retrain your custom model with the current spaCy version. For more details and available updates, run: python -m spacy validate
  warnings.warn(warn_msg)
MartinoMensio commented 4 years ago

Yes I noticed. I fixed the errors on the codebase and I'm releasing the new models now. Thanks for pointing it out

MartinoMensio commented 4 years ago

Can you try installing the 0.2.3 version? It should be fixed.

rdjondo commented 4 years ago

Hello,

I tried it with but it does not work still. I got the following error: NotFoundError: anaconda3/lib/python3.7/site-packages/tensorflow_text/python/ops/_wordpiece_tokenizer.so: undefined symbol: _ZNK10tensorflow11ResourceMgr8DoLookupERKSsSt10type_indexS2_PPNS_12ResourceBaseE

To install it, I used: pip uninstall spacy-universal-sentence-encoder

Then, pip install git+https://github.com/MartinoMensio/spacy-universal-sentence-encoder-tfhub.git This output:

Successfully built spacy-universal-sentence-encoder
ERROR: tensorflow-text 2.1.1 has requirement tensorflow<2.2,>=2.1.0, but you'll have tensorflow 2.2.0 which is incompatible.
Installing collected packages: tensorflow, spacy-universal-sentence-encoder
Successfully installed spacy-universal-sentence-encoder-0.2.2 tensorflow-2.2.0
MartinoMensio commented 4 years ago

That tensorflow-text caused many errors already. I changed now another time the dependency version declaration to force a version compatible with the tensorflow version.

Please re-run the command:

pip install git+https://github.com/MartinoMensio/spacy-universal-sentence-encoder-tfhub.git

Which should now remove tensorflow-text version 2.1.1 that you have installed and install the 2.2.1 which is compatible. Thanks for the patience :)

rdjondo commented 4 years ago

It looks like your last change fixes the issue,

Thank you @MartinoMensio !