Hack Language.evaluate

This commit is contained in:
Matthew Honnibal 2020-06-13 23:37:42 +02:00
parent 7de997c0a5
commit 4362ec7084

View File

@ -723,24 +723,26 @@ class Language(object):
DOCS: https://spacy.io/api/language#evaluate DOCS: https://spacy.io/api/language#evaluate
""" """
examples = Example.to_example_objects(examples, make_doc=self.make_doc) examples = Example.to_example_objects(examples)
if scorer is None: if scorer is None:
scorer = Scorer(pipeline=self.pipeline) scorer = Scorer(pipeline=self.pipeline)
if component_cfg is None: if component_cfg is None:
component_cfg = {} component_cfg = {}
docs = (eg.predicted for eg in examples)
for name, pipe in self.pipeline: for name, pipe in self.pipeline:
kwargs = component_cfg.get(name, {}) kwargs = component_cfg.get(name, {})
kwargs.setdefault("batch_size", batch_size) kwargs.setdefault("batch_size", batch_size)
if not hasattr(pipe, "pipe"): if not hasattr(pipe, "pipe"):
examples = _pipe(examples, pipe, kwargs) docs = _pipe(docs, pipe, kwargs)
else: else:
examples = pipe.pipe(examples, as_example=True, **kwargs) docs = pipe.pipe(docs, **kwargs)
for ex in examples: for doc, eg in zip(docs, examples):
if verbose: if verbose:
print(ex.doc) print(ex.doc)
eg.predicted = doc
kwargs = component_cfg.get("scorer", {}) kwargs = component_cfg.get("scorer", {})
kwargs.setdefault("verbose", verbose) kwargs.setdefault("verbose", verbose)
scorer.score(ex, **kwargs) scorer.score(eg, **kwargs)
return scorer return scorer
@contextmanager @contextmanager