mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-26 01:46:28 +03:00
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:
parent
901801b33b
commit
9b509aa87f
|
@ -1099,6 +1099,7 @@ class Language:
|
||||||
batch_size: int = 256,
|
batch_size: int = 256,
|
||||||
scorer: Optional[Scorer] = None,
|
scorer: Optional[Scorer] = None,
|
||||||
component_cfg: Optional[Dict[str, Dict[str, Any]]] = None,
|
component_cfg: Optional[Dict[str, Dict[str, Any]]] = None,
|
||||||
|
scorer_cfg: Optional[Dict[str, Any]] = None,
|
||||||
) -> Dict[str, Union[float, dict]]:
|
) -> Dict[str, Union[float, dict]]:
|
||||||
"""Evaluate a model's pipeline components.
|
"""Evaluate a model's pipeline components.
|
||||||
|
|
||||||
|
@ -1109,6 +1110,8 @@ class Language:
|
||||||
will be created.
|
will be created.
|
||||||
component_cfg (dict): An optional dictionary with extra keyword
|
component_cfg (dict): An optional dictionary with extra keyword
|
||||||
arguments for specific components.
|
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.
|
RETURNS (Scorer): The scorer containing the evaluation results.
|
||||||
|
|
||||||
DOCS: https://spacy.io/api/language#evaluate
|
DOCS: https://spacy.io/api/language#evaluate
|
||||||
|
@ -1126,8 +1129,10 @@ class Language:
|
||||||
raise TypeError(err)
|
raise TypeError(err)
|
||||||
if component_cfg is None:
|
if component_cfg is None:
|
||||||
component_cfg = {}
|
component_cfg = {}
|
||||||
|
if scorer_cfg is None:
|
||||||
|
scorer_cfg = {}
|
||||||
if scorer is None:
|
if scorer is None:
|
||||||
kwargs = component_cfg.get("scorer", {})
|
kwargs = dict(scorer_cfg)
|
||||||
kwargs.setdefault("verbose", verbose)
|
kwargs.setdefault("verbose", verbose)
|
||||||
kwargs.setdefault("nlp", self)
|
kwargs.setdefault("nlp", self)
|
||||||
scorer = Scorer(**kwargs)
|
scorer = Scorer(**kwargs)
|
||||||
|
|
|
@ -118,7 +118,7 @@ def test_overfitting_IO():
|
||||||
|
|
||||||
# Test scoring
|
# Test scoring
|
||||||
scores = nlp.evaluate(
|
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_f"] == 1.0
|
||||||
assert scores["cats_score"] == 1.0
|
assert scores["cats_score"] == 1.0
|
||||||
|
|
|
@ -302,6 +302,7 @@ Evaluate a model's pipeline components.
|
||||||
| `batch_size` | int | The batch size to use. |
|
| `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. |
|
| `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`. |
|
| `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. |
|
| **RETURNS** | `Dict[str, Union[float, dict]]` | A dictionary of evaluation scores. |
|
||||||
|
|
||||||
## Language.use_params {#use_params tag="contextmanager, method"}
|
## Language.use_params {#use_params tag="contextmanager, method"}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user