Move Language.evaluate scorer config to new arg

Move `Language.evaluate` scorer config from `component_cfg` to separate
argument `scorer_cfg`.
This commit is contained in:
Adriane Boyd 2020-07-31 11:02:17 +02:00
parent 901801b33b
commit 9b509aa87f
3 changed files with 8 additions and 2 deletions

View File

@ -1099,6 +1099,7 @@ class Language:
batch_size: int = 256,
scorer: Optional[Scorer] = None,
component_cfg: Optional[Dict[str, Dict[str, Any]]] = None,
scorer_cfg: Optional[Dict[str, Any]] = None,
) -> Dict[str, Union[float, dict]]:
"""Evaluate a model's pipeline components.
@ -1109,6 +1110,8 @@ class Language:
will be created.
component_cfg (dict): An optional dictionary with extra keyword
arguments for specific components.
scorer_cfg (dict): An optional dictionary with extra keyword arguments
for the scorer.
RETURNS (Scorer): The scorer containing the evaluation results.
DOCS: https://spacy.io/api/language#evaluate
@ -1126,8 +1129,10 @@ class Language:
raise TypeError(err)
if component_cfg is None:
component_cfg = {}
if scorer_cfg is None:
scorer_cfg = {}
if scorer is None:
kwargs = component_cfg.get("scorer", {})
kwargs = dict(scorer_cfg)
kwargs.setdefault("verbose", verbose)
kwargs.setdefault("nlp", self)
scorer = Scorer(**kwargs)

View File

@ -118,7 +118,7 @@ def test_overfitting_IO():
# Test scoring
scores = nlp.evaluate(
train_examples, component_cfg={"scorer": {"positive_label": "POSITIVE"}}
train_examples, scorer_cfg={"positive_label": "POSITIVE"}
)
assert scores["cats_f"] == 1.0
assert scores["cats_score"] == 1.0

View File

@ -302,6 +302,7 @@ Evaluate a model's pipeline components.
| `batch_size` | int | The batch size to use. |
| `scorer` | `Scorer` | Optional [`Scorer`](/api/scorer) to use. If not passed in, a new one will be created. |
| `component_cfg` | `Dict[str, dict]` | Optional dictionary of keyword arguments for components, keyed by component names. Defaults to `None`. |
| `scorer_cfg` | `Dict[str, Any]` | Optional dictionary of keyword arguments for the `Scorer`. Defaults to `None`. |
| **RETURNS** | `Dict[str, Union[float, dict]]` | A dictionary of evaluation scores. |
## Language.use_params {#use_params tag="contextmanager, method"}