Auto-exclude disabled when calling from_disk during load (#4708)

This commit is contained in:
Ines Montani 2019-11-25 16:01:22 +01:00 committed by Matthew Honnibal
parent 2160ecfc92
commit 5b36dec7eb
2 changed files with 24 additions and 1 deletions

View File

@ -0,0 +1,23 @@
# coding: utf8
from __future__ import unicode_literals
from spacy.util import load_model_from_path
from spacy.lang.en import English
from ..util import make_tempdir
def test_issue4707():
"""Tests that disabled component names are also excluded from nlp.from_disk
by default when loading a model.
"""
nlp = English()
nlp.add_pipe(nlp.create_pipe("sentencizer"))
nlp.add_pipe(nlp.create_pipe("entity_ruler"))
assert nlp.pipe_names == ["sentencizer", "entity_ruler"]
exclude = ["tokenizer", "sentencizer"]
with make_tempdir() as tmpdir:
nlp.to_disk(tmpdir, exclude=exclude)
new_nlp = load_model_from_path(tmpdir, disable=exclude)
assert "sentencizer" not in new_nlp.pipe_names
assert "entity_ruler" in new_nlp.pipe_names

View File

@ -208,7 +208,7 @@ def load_model_from_path(model_path, meta=False, **overrides):
factory = factories.get(name, name) factory = factories.get(name, name)
component = nlp.create_pipe(factory, config=config) component = nlp.create_pipe(factory, config=config)
nlp.add_pipe(component, name=name) nlp.add_pipe(component, name=name)
return nlp.from_disk(model_path) return nlp.from_disk(model_path, exclude=disable)
def load_model_from_init_py(init_file, **overrides): def load_model_from_init_py(init_file, **overrides):