Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant load model after adding custom component in pipeline #1984

Closed
duesXMachine opened this issue Feb 14, 2018 · 3 comments
Closed

Cant load model after adding custom component in pipeline #1984

duesXMachine opened this issue Feb 14, 2018 · 3 comments
Labels
feat / pipeline Feature: Processing pipeline and components usage General spaCy usage

Comments

@duesXMachine
Copy link

Hi, I trained a NER from scratch with custom dataset without any other component in pipeline. I loaded the model and added another component(Phrase Matcher) to existing pipeline and trained NER again.Now I cant load the new saved model.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/deusxmachine/.local/lib/python2.7/site-packages/spacy/__init__.py", line 19, in load
    return util.load_model(name, **overrides)
  File "/home/deusxmachine/.local/lib/python2.7/site-packages/spacy/util.py", line 116, in load_model
    return load_model_from_path(Path(name), **overrides)
  File "/home/deusxmachine/.local/lib/python2.7/site-packages/spacy/util.py", line 156, in load_model_from_path
    component = nlp.create_pipe(name, config=config)
  File "/home/deusxmachine/.local/lib/python2.7/site-packages/spacy/language.py", line 215, in create_pipe
    raise KeyError("Can't find factory for '{}'.".format(name))
KeyError: u"Can't find factory for 'my_component'."

Your Environment

  • Operating System: Linux-4.13.0-32-generic-x86_64-with-Ubuntu-17.10-artful
  • Python Version Used: 2.7.14
  • spaCy Version Used: 2.0.7
@thetravelingsalesman
Copy link

thetravelingsalesman commented Feb 28, 2018

Also having the same issue with default en_core_web_lg/sm.

@ines ines added usage General spaCy usage feat / pipeline Feature: Processing pipeline and components labels Mar 27, 2018
@ines
Copy link
Member

ines commented Mar 27, 2018

Sorry for only getting to this now. The reason you're seeing this error is because spaCy doesn't have a built-in factory for your component. When the model is loaded, spaCy will check the meta.json's "pipeline" and call nlp.create_pipe on each of them. This works fine for the built-ins – but if you're using custom components, you need to tell spaCy how to initialize it. For example:

Language.factories['my_component'] = lambda nlp, **cfg: MyComponent(nlp, **cfg)

For more details, check out this thread over on the Prodigy forum where I share a full code example of a model's __init__.py using a custom PhraseMatcher component.

Once the new matcher is implemented in v2.1.0 (see #1971), I'd love to turn this into a full end-to-end spaCy tutorial.

@lock
Copy link

lock bot commented May 7, 2018

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.

@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat / pipeline Feature: Processing pipeline and components usage General spaCy usage
Projects
None yet
Development

No branches or pull requests

3 participants