Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

spacy

I'm using spacy for natural language processing with the following code in jupyter notebook.

# Import spacy
import spacy

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

The following error occur

---------------------------------------------------------------------------
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'

To summarize it is

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

Just a note: I have install and link spacy.load('en') properly in anaconda prompt as administrator python -m spacy download en already. Here's the result in anaconda prompt

(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')
like image 783
Win Supan Avatar asked Sep 15 '18 13:09

Win Supan


2 Answers

pip uninstall msgpack-python
pip install msgpack

Note that: my prompt happens to underscored that "regex version(2018.7.11) is incompatible with spacy which wants regex==2017.4.5" however my spacy still works normally now!

Btw, great thanks to @Ines Montani

like image 149
Win Supan Avatar answered Nov 16 '22 16:11

Win Supan


I am using Conda Python 3 on a Windows Box. Installing spacy installed the 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

and I got the same error doing:

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

Error:

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

FIX: reinstalled msgpack-python using:

conda install -c anaconda msgpack-python

this updated msgpack-python:

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

and the error got fixed!

like image 39
Anup Mishra Avatar answered Nov 16 '22 16:11

Anup Mishra