Skip to content

Commit

Permalink
Fix bug in Language.evaluate for components without .pipe (explosion#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ines authored Nov 16, 2019
1 parent bdfb696 commit 3bd1505
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion spacy/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ def evaluate(
kwargs = component_cfg.get(name, {})
kwargs.setdefault("batch_size", batch_size)
if not hasattr(pipe, "pipe"):
docs = _pipe(pipe, docs, kwargs)
docs = _pipe(docs, pipe, kwargs)
else:
docs = pipe.pipe(docs, **kwargs)
for doc, gold in zip(docs, golds):
Expand Down
14 changes: 14 additions & 0 deletions spacy/tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ def test_language_evaluate(nlp):
nlp.evaluate([text, gold])


def test_evaluate_no_pipe(nlp):
"""Test that docs are processed correctly within Language.pipe if the
component doesn't expose a .pipe method."""

def pipe(doc):
return doc

text = "hello world"
annots = {"cats": {"POSITIVE": 1.0, "NEGATIVE": 0.0}}
nlp = Language(Vocab())
nlp.add_pipe(pipe)
nlp.evaluate([(text, annots)])


def vector_modification_pipe(doc):
doc.vector += 1
return doc
Expand Down

0 comments on commit 3bd1505

Please sign in to comment.