mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 17:36:30 +03:00
Merge pull request #6273 from adrianeboyd/bugfix/detailed-scores-in-evaluate2
This commit is contained in:
commit
6523f2daac
|
@ -93,6 +93,7 @@ def evaluate(
|
|||
"SPEED": "speed",
|
||||
}
|
||||
results = {}
|
||||
data = {}
|
||||
for metric, key in metrics.items():
|
||||
if key in scores:
|
||||
if key == "cats_score":
|
||||
|
@ -101,19 +102,30 @@ def evaluate(
|
|||
results[metric] = f"{scores[key]:.0f}"
|
||||
else:
|
||||
results[metric] = f"{scores[key]*100:.2f}"
|
||||
data = {re.sub(r"[\s/]", "_", k.lower()): v for k, v in results.items()}
|
||||
data[re.sub(r"[\s/]", "_", key.lower())] = scores[key]
|
||||
|
||||
msg.table(results, title="Results")
|
||||
|
||||
if "morph_per_feat" in scores:
|
||||
if scores["morph_per_feat"]:
|
||||
print_prf_per_type(msg, scores["morph_per_feat"], "MORPH", "feat")
|
||||
data["morph_per_feat"] = scores["morph_per_feat"]
|
||||
if "dep_las_per_type" in scores:
|
||||
if scores["dep_las_per_type"]:
|
||||
print_prf_per_type(msg, scores["dep_las_per_type"], "LAS", "type")
|
||||
data["dep_las_per_type"] = scores["dep_las_per_type"]
|
||||
if "ents_per_type" in scores:
|
||||
if scores["ents_per_type"]:
|
||||
print_ents_per_type(msg, scores["ents_per_type"])
|
||||
print_prf_per_type(msg, scores["ents_per_type"], "NER", "type")
|
||||
data["ents_per_type"] = scores["ents_per_type"]
|
||||
if "cats_f_per_type" in scores:
|
||||
if scores["cats_f_per_type"]:
|
||||
print_textcats_f_per_cat(msg, scores["cats_f_per_type"])
|
||||
print_prf_per_type(msg, scores["cats_f_per_type"], "Textcat F", "label")
|
||||
data["cats_f_per_type"] = scores["cats_f_per_type"]
|
||||
if "cats_auc_per_type" in scores:
|
||||
if scores["cats_auc_per_type"]:
|
||||
print_textcats_auc_per_cat(msg, scores["cats_auc_per_type"])
|
||||
data["cats_auc_per_type"] = scores["cats_auc_per_type"]
|
||||
|
||||
if displacy_path:
|
||||
factory_names = [nlp.get_pipe_meta(pipe).factory for pipe in nlp.pipe_names]
|
||||
|
@ -157,7 +169,7 @@ def render_parses(
|
|||
file_.write(html)
|
||||
|
||||
|
||||
def print_ents_per_type(msg: Printer, scores: Dict[str, Dict[str, float]]) -> None:
|
||||
def print_prf_per_type(msg: Printer, scores: Dict[str, Dict[str, float]], name: str, type: str) -> None:
|
||||
data = [
|
||||
(k, f"{v['p']*100:.2f}", f"{v['r']*100:.2f}", f"{v['f']*100:.2f}")
|
||||
for k, v in scores.items()
|
||||
|
@ -166,20 +178,7 @@ def print_ents_per_type(msg: Printer, scores: Dict[str, Dict[str, float]]) -> No
|
|||
data,
|
||||
header=("", "P", "R", "F"),
|
||||
aligns=("l", "r", "r", "r"),
|
||||
title="NER (per type)",
|
||||
)
|
||||
|
||||
|
||||
def print_textcats_f_per_cat(msg: Printer, scores: Dict[str, Dict[str, float]]) -> None:
|
||||
data = [
|
||||
(k, f"{v['p']*100:.2f}", f"{v['r']*100:.2f}", f"{v['f']*100:.2f}")
|
||||
for k, v in scores.items()
|
||||
]
|
||||
msg.table(
|
||||
data,
|
||||
header=("", "P", "R", "F"),
|
||||
aligns=("l", "r", "r", "r"),
|
||||
title="Textcat F (per label)",
|
||||
title=f"{name} (per {type})",
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ function formatAccuracy(data) {
|
|||
? null
|
||||
: {
|
||||
label,
|
||||
value: value.toFixed(2),
|
||||
value: (value * 100).toFixed(2),
|
||||
help: MODEL_META[label],
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user