Hi,
I'm trying to package a model with one custom pipe "entity_optimiser" using spacy package command and amending the generated init to include writing to Language.factories and the setup.py to include all packages. On loading the model it can't find my modules and the custom component. Everything works as expected when using the source code.
Please can you take a look below if anything stands out as obviously wrong?
Model directory - abridged
| MANIFEST.in
| meta.json
| setup.py
|
+---dist
| en_cit_nb_ner-20.1.23.tar.gz
|
+---en_cit_nb_ner
| | en_cit_nb_ner-20.01.23
| | meta.json
| | __init__.py
| |
| \---en_cit_nb_ner
| | meta.json
| | tokenizer
| | __init__.py
| |
| +---entity_optimiser
| | | address_instance_label_prior_vector
| | | data.json
| | | entity_optimiser_master.py
| | | __init__.py
| | |
| | +---spacy_en_model
| | | |
| | | +---ner
| | | |
| | | +---parser
| | | |
| | | +---tagger
| | | |
| | | \---vocab
| |
| +---ner
| |
| +---vocab
|
\---en_cit_nb_ner.egg-info
init in top directory contains:
from __future__ import unicode_literals
from pathlib import Path
from spacy.util import load_model_from_init_py, get_model_meta
from spacy.language import Language
from .en_cit_nb_ner.entity_optimiser.entity_optimiser_master import Entity_Optimiser
__version__ = get_model_meta(Path(__file__).parent)['version']
def load(**overrides):
return load_model_from_init_py(__file__, **overrides)
Language.factories["entity_optimiser"] = lambda nlp, **cfg: Entity_Optimiser()
Here is the error
Python 3.6.7 (default, Jul 2 2019, 02:21:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
>>> nlp = spacy.load("en_cit_nb_ner")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Anaconda351\envs\python_36\lib\site-packages\spacy\__init__.py", line 27, in load
return util.load_model(name, **overrides)
File "C:\Anaconda351\envs\python_36\lib\site-packages\spacy\util.py", line 134, in load_model
return load_model_from_package(name, **overrides)
File "C:\Anaconda351\envs\python_36\lib\site-packages\spacy\util.py", line 154, in load_model_from_package
cls = importlib.import_module(name)
File "C:\Anaconda351\envs\python_36\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Anaconda351\envs\python_36\lib\site-packages\en_cit_nb_ner\__init__.py", line 9, in <module>
from .en_cit_nb_ner.entity_optimiser.entity_optimiser_master import Entity_Optimiser
File "C:\Anaconda351\envs\python_36\lib\site-packages\en_cit_nb_ner\en_cit_nb_ner\__init__.py", line 11, in <module>
from entity_optimiser_master import Entity_Optimiser
ModuleNotFoundError: No module named 'entity_optimiser_master'