web-dev-qa-db-fra.com

python spacy TypeError: unpackb () a un argument de mot clé inattendu, 'raw'

J'utilise spacy pour le traitement du langage naturel avec le code suivant dans jupyter notebook.

# Import spacy
import spacy

# Instantiate the English model: nlp
nlp = spacy.load('en')

L'erreur suivante se produit

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-3370ec3212e0> in <module>()
      3 
      4 # Instantiate the English model: nlp
----> 5 nlp = spacy.load('en')
      6 

~\Anaconda3\lib\site-packages\spacy\__init__.py in load(name, **overrides)
     13     if depr_path not in (True, False, None):
     14         deprecation_warning(Warnings.W001.format(path=depr_path))
---> 15     return util.load_model(name, **overrides)
     16 
     17 

~\Anaconda3\lib\site-packages\spacy\util.py in load_model(name, **overrides)
    110     if isinstance(name, basestring_):  # in data dir / shortcut
    111         if name in set([d.name for d in data_path.iterdir()]):
--> 112             return load_model_from_link(name, **overrides)
    113         if is_package(name):  # installed as package
    114             return load_model_from_package(name, **overrides)

~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_link(name, **overrides)
    127     except AttributeError:
    128         raise IOError(Errors.E051.format(name=name))
--> 129     return cls.load(**overrides)
    130 
    131 

~\Anaconda3\lib\site-packages\spacy\data\en\__init__.py in load(**overrides)
     10 
     11 def load(**overrides):
---> 12     return load_model_from_init_py(__file__, **overrides)

~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_init_py(init_file, **overrides)
    171     if not model_path.exists():
    172         raise IOError(Errors.E052.format(path=path2str(data_path)))
--> 173     return load_model_from_path(data_path, meta, **overrides)
    174 
    175 

~\Anaconda3\lib\site-packages\spacy\util.py in load_model_from_path(model_path, meta, **overrides)
    154             component = nlp.create_pipe(name, config=config)
    155             nlp.add_pipe(component, name=name)
--> 156     return nlp.from_disk(model_path)
    157 
    158 

~\Anaconda3\lib\site-packages\spacy\language.py in from_disk(self, path, disable)
    651         if not (path / 'vocab').exists():
    652             exclude['vocab'] = True
--> 653         util.from_disk(path, deserializers, exclude)
    654         self._path = path
    655         return self

~\Anaconda3\lib\site-packages\spacy\util.py in from_disk(path, readers, exclude)
    509     for key, reader in readers.items():
    510         if key not in exclude:
--> 511             reader(path / key)
    512     return path
    513 

~\Anaconda3\lib\site-packages\spacy\language.py in <lambda>(p)
    640             ('vocab', lambda p: (
    641                 self.vocab.from_disk(p) and _fix_pretrained_vectors_name(self))),
--> 642             ('tokenizer', lambda p: self.tokenizer.from_disk(p, vocab=False)),
    643         ))
    644         for name, proc in self.pipeline:

tokenizer.pyx in spacy.tokenizer.Tokenizer.from_disk()

tokenizer.pyx in spacy.tokenizer.Tokenizer.from_bytes()

~\Anaconda3\lib\site-packages\spacy\util.py in from_bytes(bytes_data, setters, exclude)
    488 
    489 def from_bytes(bytes_data, setters, exclude):
--> 490     msg = msgpack.loads(bytes_data, raw=False)
    491     for key, setter in setters.items():
    492         if key not in exclude and key in msg:

~\Anaconda3\lib\site-packages\msgpack_numpy.py in unpackb(packed, **kwargs)
    182     object_hook = kwargs.get('object_hook')
    183     kwargs['object_hook'] = functools.partial(decode, chain=object_hook)
--> 184     return _unpackb(packed, **kwargs)
    185 
    186 load = unpack

msgpack/_unpacker.pyx in msgpack._unpacker.unpackb()

TypeError: unpackb() got an unexpected keyword argument 'raw'

Pour résumer c'est

TypeError: unpackb() got an unexpected keyword argument 'raw'

Juste une remarque: J'ai déjà installé et lié spacy.load('en') correctement dans l'invite anaconda en tant qu'administrateur python -m spacy download en. Voici le résultat dans l'invite anaconda

(base) C:\WINDOWS\system32>python -m spacy download en
Requirement already satisfied: en_core_web_sm==2.0.0 from https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-2.0.0/en_core_web_sm-2.0.0.tar.gz#Egg=en_core_web_sm==2.0.0 in c:\users\winsu\anaconda3\lib\site-packages (2.0.0)

    Linking successful
    C:\Users\winsu\Anaconda3\lib\site-packages\en_core_web_sm -->
    C:\Users\winsu\Anaconda3\lib\site-packages\spacy\data\en

    You can now load the model via spacy.load('en')
3
Win Supan
pip uninstall msgpack-python
pip install msgpack

Notez que: my Prompt a souligné que "la version de regex (2018.7.11) est incompatible avec spacy qui veut regex == 2017.4.5", mais mon spacy fonctionne toujours normalement maintenant!

Btw, merci beaucoup à @Ines Montani

5
Win Supan

J'utilise Conda Python 3 sur une Windows Box. L'installation de spacy a installé le msgpack:

Local\Continuum\anaconda3>conda list
# packages in environment at C:\Users\akmm94\AppData\Local\Continuum\anaconda3:
#
# Name                    Version                   Build  Channel
msgpack-python            0.5.1            py36he980bc4_0

et j'ai eu la même erreur en faisant:

import spacy
nlp = spacy.load('en')

Erreur:

TypeError: unpackb() got an unexpected keyword argument 'raw'

CORRECTIF: réinstallé msgpack-python en utilisant:

conda install -c anaconda msgpack-python

ce msgpack-python mis à jour:

msgpack-python:  0.5.1-py36he980bc4_0             --> 0.5.6-py36he980bc4_1 anaconda

et l'erreur a été corrigée!

1
Anup Mishra