mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 01:16:28 +03:00
Merge pull request #6229 from svlandeg/bugfix/disabled
This commit is contained in:
commit
b7cb9d95e4
|
@ -456,6 +456,8 @@ class Errors:
|
|||
"issue tracker: http://github.com/explosion/spaCy/issues")
|
||||
|
||||
# TODO: fix numbering after merging develop into master
|
||||
E900 = ("Could not run the full 'nlp' pipeline for evaluation. If you specified "
|
||||
"frozen components, make sure they were already initialized and trained. ")
|
||||
E901 = ("Failed to remove existing output directory: {path}. If your "
|
||||
"config and the components you train change between runs, a "
|
||||
"non-empty output directory can lead to stale pipeline data. To "
|
||||
|
|
|
@ -1034,6 +1034,9 @@ class Language:
|
|||
)
|
||||
)
|
||||
disable = to_disable
|
||||
# DisabledPipes will restore the pipes in 'disable' when it's done, so we need to exclude
|
||||
# those pipes that were already disabled.
|
||||
disable = [d for d in disable if d not in self._disabled]
|
||||
return DisabledPipes(self, disable)
|
||||
|
||||
def make_doc(self, text: str) -> Doc:
|
||||
|
|
|
@ -129,6 +129,7 @@ def test_enable_pipes_method(nlp, name):
|
|||
|
||||
@pytest.mark.parametrize("name", ["my_component"])
|
||||
def test_disable_pipes_context(nlp, name):
|
||||
"""Test that an enabled component stays enabled after running the context manager."""
|
||||
nlp.add_pipe("new_pipe", name=name)
|
||||
assert nlp.has_pipe(name)
|
||||
with nlp.select_pipes(disable=name):
|
||||
|
@ -136,6 +137,18 @@ def test_disable_pipes_context(nlp, name):
|
|||
assert nlp.has_pipe(name)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("name", ["my_component"])
|
||||
def test_disable_pipes_context_restore(nlp, name):
|
||||
"""Test that a disabled component stays disabled after running the context manager."""
|
||||
nlp.add_pipe("new_pipe", name=name)
|
||||
assert nlp.has_pipe(name)
|
||||
nlp.disable_pipes(name)
|
||||
assert not nlp.has_pipe(name)
|
||||
with nlp.select_pipes(disable=name):
|
||||
assert not nlp.has_pipe(name)
|
||||
assert not nlp.has_pipe(name)
|
||||
|
||||
|
||||
def test_select_pipes_list_arg(nlp):
|
||||
for name in ["c1", "c2", "c3"]:
|
||||
nlp.add_pipe("new_pipe", name=name)
|
||||
|
|
|
@ -249,7 +249,10 @@ def create_evaluation_callback(
|
|||
|
||||
def evaluate() -> Tuple[float, Dict[str, float]]:
|
||||
dev_examples = list(dev_corpus(nlp))
|
||||
try:
|
||||
scores = nlp.evaluate(dev_examples)
|
||||
except KeyError as e:
|
||||
raise KeyError(Errors.E900) from e
|
||||
# Calculate a weighted sum based on score_weights for the main score.
|
||||
# We can only consider scores that are ints/floats, not dicts like
|
||||
# entity scores per type etc.
|
||||
|
|
Loading…
Reference in New Issue
Block a user