explosion / spaCy

💫 Industrial-strength Natural Language Processing (NLP) in Python
https://spacy.io
MIT License
29.69k stars 4.36k forks source link

multiprocessing: Can't pickle local object 'build_ngram_suggester.<locals>.ngram_suggester #12485

Closed vitaly-d closed 1 year ago

vitaly-d commented 1 year ago

spacy.ngram_suggester.v1 and spacy.ngram_range_suggester.v1 suggesters don't seem to be compatible with multiprocessing: it fails withAttributeError: Can't pickle local object 'build_ngram_suggester.<locals>.ngram_suggester' .

How to reproduce the behaviour

the spancat_multiprocessing_fail.py script from the attached spancat_multiprocessing.zip fails with AttributeError: Can't pickle local object 'build_ngram_suggester.<locals>.ngram_suggester'

Workaround

the spancat_multiprocessing_ok.py script works. It contains 'custom' suggester that is a copy of https://github.com/explosion/spaCy/blob/372a90885e849a286c27103bece93ad8a02c842e/spacy/pipeline/spancat.py#L86 wrapped in a python class.

Info about spaCy

adrianeboyd commented 1 year ago

Thanks for the report, I'm surprised this hasn't come up sooner!

github-actions[bot] commented 1 year ago

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.