From 5b36dec7eb505b31bbbfa4bb448fdc35eb738cd7 Mon Sep 17 00:00:00 2001 From: Ines Montani Date: Mon, 25 Nov 2019 16:01:22 +0100 Subject: [PATCH] Auto-exclude disabled when calling from_disk during load (#4708) --- spacy/tests/regression/test_issue4707.py | 23 +++++++++++++++++++++++ spacy/util.py | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 spacy/tests/regression/test_issue4707.py diff --git a/spacy/tests/regression/test_issue4707.py b/spacy/tests/regression/test_issue4707.py new file mode 100644 index 000000000..e710881d7 --- /dev/null +++ b/spacy/tests/regression/test_issue4707.py @@ -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 diff --git a/spacy/util.py b/spacy/util.py index 57ed244f8..9b96b2f5e 100644 --- a/spacy/util.py +++ b/spacy/util.py @@ -208,7 +208,7 @@ def load_model_from_path(model_path, meta=False, **overrides): factory = factories.get(name, name) component = nlp.create_pipe(factory, config=config) 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):