multi-processing.py example code returns a joblib error (macOS, Spacy2.0.3)
I'm running the example multi-processing script referenced in the Spacy docs at https://spacy.io/usage/processing-pipelines#multithreading. At github https://github.com/explosion/spacy/blob/master/examples/pipeline/multi_processing.py
I get the following output:
> python3 multi_processing.py '/Users/me/Documents/devl/quick_entity/data/spacy_multi_example', 'en_core_web_sm'
Loaded model 'en_core_web_sm'
Loading IMDB data...
Processing texts...
Traceback (most recent call last):
File "multi_processing.py", line 79, in <module>
plac.call(main)
File "/Users/me/Documents/devl/quick_entity/myenv/lib/python3.6/site-packages/plac_core.py", line 328, in call
cmd, result = parser.consume(arglist)
File "/Users/me/Documents/devl/quick_entity/myenv/lib/python3.6/site-packages/plac_core.py", line 207, in consume
return cmd, self.func(*(args + varargs + extraopts), **kwargs)
File "multi_processing.py", line 43, in main
executor(tasks)
File "/Users/me/Documents/devl/quick_entity/myenv/lib/python3.6/site-packages/joblib/parallel.py", line 789, in __call__
self.retrieve()
File "/Users/me/Documents/devl/quick_entity/myenv/lib/python3.6/site-packages/joblib/parallel.py", line 699, in retrieve
self._output.extend(job.get(timeout=self.timeout))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 644, in get
raise self._value
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 424, in _handle_tasks
put(task)
File "/Users/me/Documents/devl/quick_entity/myenv/lib/python3.6/site-packages/joblib/pool.py", line 371, in send
CustomizablePickler(buffer, self._reducers).dump(obj)
AttributeError: Can't pickle local object 'FeatureExtracter.<locals>.feature_extracter_fwd'
I'm getting the same error on my own code when I try to enable multiprocessing so any suggestions about how to get this working (or possible workarounds) would be appreciated.
Info about spaCy
- spaCy version: 2.0.3
- Platform: Darwin-16.7.0-x86_64-i386-64bit
- Python version: 3.6.2
- Models: en, en_core_web_lg
pip freeze
aniso8601==1.3.0 certifi==2017.11.5 chardet==3.0.4 click==6.7 cymem==1.31.2 cytoolz==0.8.2 dill==0.2.7.1 en-core-web-sm==2.0.0 Flask==0.12.2 Flask-RESTful==0.3.6 ftfy==4.4.3 html5lib==0.999999999 idna==2.6 itsdangerous==0.24 Jinja2==2.10 joblib==0.11 MarkupSafe==1.0 more-itertools==3.2.0 msgpack-numpy==0.4.1 msgpack-python==0.4.8 murmurhash==0.28.0 numpy==1.13.3 pathlib==1.0.1 plac==0.9.6 preshed==1.0.0 python-dateutil==2.6.1 pytz==2017.3 regex==2017.4.5 requests==2.18.4 six==1.11.0 spacy==2.0.3 termcolor==1.1.0 thinc==6.10.1 toolz==0.8.2 tqdm==4.19.4 ujson==1.35 urllib3==1.22 wcwidth==0.1.7 webencodings==0.5.1 Werkzeug==0.12.2 wrapt==1.10.11
Same issue on Spacy 2.0.5 .
Same error with Spacy 2.0.3
I am getting following error with this code
usage: [-h] [-n 4] [-b 1000] [-l 10000] output_dir [model] error: too few arguments
- Operating System: Windows 7
- Python Version Used: 2.7
- spaCy Version Used: 2.0.3
- Environment Information: en, en_core_web_sm

Same error with Spacy 2.0.4.
Same error with Spacy 2.0.8.
any update?
Is this because pickle doesn't support nested functions? The error message refers to FeatureExtracter.<locals>.feature_extracter_fwd, which is a nested function.
Version 2.0.10. and the error still persists.
Version 2.0.11, and still facing this error. @honnibal @ines is a fix to this on the cards? Any way we can help out with this?
@dasguptar I think that this is related to https://github.com/explosion/spaCy/issues/2075 and won't be resolved until 2.1.x
One workaround is to make nlp a local variable of transform_texts
If you use joblib to parallelize things should work just fine
Ah right, thanks! I was a bit premature in posting that comment because I made significant changes from the example for processing something :grimacing:
@korbonits could you elaborate further how you got parallelization to work with joblib ?
hmmm it might be working now?
import spacy
nlp = spacy.load("en")
results = [nlp(string).vector for t in tqdm(list of strings)]
seems to be MUCH faster than using joblib
import multiprocessing as mp
from joblib import Parallel, delayed
num_cores = mp.cpu_count()
def get_vector(string):
s = nlp(string)
return s.vector
results = Parallel(n_jobs=num_cores)(delayed(func)(row) for row in tqdm(data))
Seems like my workaround doesn't work anymore. Try the list comprehension
Should be working on the spacy-nightly version now. Thanks for your patience with this.
Still facing issues
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.