From 65e41a52ddfe3266039443743fcf6d197de55909 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Thu, 29 Sep 2022 10:39:36 +0200 Subject: [PATCH] Reverting unnecessary changes. Removing unused default values. Renaming variables in find-cli tests. --- spacy/cli/find_threshold.py | 1 - spacy/scorer.py | 12 ++++++++---- spacy/tests/test_cli.py | 14 +++++++------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/spacy/cli/find_threshold.py b/spacy/cli/find_threshold.py index 6d8935512..41210a0c6 100644 --- a/spacy/cli/find_threshold.py +++ b/spacy/cli/find_threshold.py @@ -13,7 +13,6 @@ from ._util import app, Arg, Opt, import_code, setup_gpu from .. import util _DEFAULTS = { - "average": "micro", "n_trials": 10, "use_gpu": -1, "gold_preproc": False, diff --git a/spacy/scorer.py b/spacy/scorer.py index 74402b466..ac58b9473 100644 --- a/spacy/scorer.py +++ b/spacy/scorer.py @@ -21,7 +21,13 @@ MISSING_VALUES = frozenset([None, 0, ""]) class PRFScore: """A precision / recall / F score.""" - def __init__(self, *, tp: int = 0, fp: int = 0, fn: int = 0) -> None: + def __init__( + self, + *, + tp: int = 0, + fp: int = 0, + fn: int = 0 + ) -> None: self.tp = tp self.fp = fp self.fn = fn @@ -37,9 +43,7 @@ class PRFScore: def __add__(self, other): return PRFScore( - tp=self.tp + other.tp, - fp=self.fp + other.fp, - fn=self.fn + other.fn, + tp=self.tp + other.tp, fp=self.fp + other.fp, fn=self.fn + other.fn, ) def score_set(self, cand: set, gold: set) -> None: diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 7b5bc88c3..c690e9e05 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -889,8 +889,8 @@ def test_cli_find_threshold(capsys): def init_nlp( components: Tuple[Tuple[str, Dict[str, Any]], ...] = () ) -> Tuple[Language, List[Example]]: - _nlp = English() - textcat: TextCategorizer = _nlp.add_pipe( # type: ignore + new_nlp = English() + textcat: TextCategorizer = new_nlp.add_pipe( # type: ignore factory_name="textcat_multilabel", name="tc_multi", config={"threshold": 0.9}, @@ -901,17 +901,17 @@ def test_cli_find_threshold(capsys): # Append additional components to pipeline. for cfn, comp_config in components: - comp = _nlp.add_pipe(cfn, config=comp_config) + comp = new_nlp.add_pipe(cfn, config=comp_config) if isinstance(comp, TextCategorizer): for label in textcat_labels: comp.add_label(label) - _examples = make_examples(_nlp) - _nlp.initialize(get_examples=lambda: _examples) + new_examples = make_examples(new_nlp) + new_nlp.initialize(get_examples=lambda: new_examples) for i in range(5): - _nlp.update(_examples) + new_nlp.update(new_examples) - return _nlp, _examples + return new_nlp, new_examples with make_tempdir() as docs_dir: # Check whether find_threshold() identifies lowest threshold above 0 as (first) ideal threshold, as this matches