From e3de12fd1e863fa5fcdafc899c400e92bc96c16c Mon Sep 17 00:00:00 2001 From: Lj Miranda Date: Wed, 26 Apr 2023 09:38:10 +0800 Subject: [PATCH] Add spans in spacy benchmark The current implementation of spaCy benchmark accuracy / spacy evaluate doesn't include the "spans" type, so calling the command doesn't render the HTML displaCy file needed. This PR attempts to fix that by creating a new parameter for "spans" and calling the appropriate displaCy value. --- spacy/cli/evaluate.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spacy/cli/evaluate.py b/spacy/cli/evaluate.py index 8f3d6b859..e44ac2dc7 100644 --- a/spacy/cli/evaluate.py +++ b/spacy/cli/evaluate.py @@ -122,6 +122,8 @@ def evaluate( docs = list(nlp.pipe(ex.reference.text for ex in dev_dataset[:displacy_limit])) render_deps = "parser" in factory_names render_ents = "ner" in factory_names + render_spans = "spancat" in factory_names + render_parses( docs, displacy_path, @@ -129,6 +131,7 @@ def evaluate( limit=displacy_limit, deps=render_deps, ents=render_ents, + spans=render_spans, ) msg.good(f"Generated {displacy_limit} parses as HTML", displacy_path) @@ -182,6 +185,7 @@ def render_parses( limit: int = 250, deps: bool = True, ents: bool = True, + spans: bool = True, ): docs[0].user_data["title"] = model_name if ents: @@ -195,6 +199,11 @@ def render_parses( with (output_path / "parses.html").open("w", encoding="utf8") as file_: file_.write(html) + if spans: + html = displacy.render(docs[:limit], style="spans", page=True) + with (output_path / "spans.html").open("w", encoding="utf8") as file_: + file_.write(html) + def print_prf_per_type( msg: Printer, scores: Dict[str, Dict[str, float]], name: str, type: str