Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to report results #53

Merged
merged 6 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion models/v0.2.0/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ spacy-huggingface-hub
build
pip==22.0.2
sentencepiece
protobuf
protobuf
typer
pandas
tabulate
77 changes: 77 additions & 0 deletions models/v0.2.0/scripts/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from pathlib import Path
from typing import Any

import typer
import pandas as pd
from srsly import read_json
from wasabi import msg


def report(
indir: Path = typer.Argument(..., help="Path to the evaluations directory.")
):
"""Return a table of evaluation results

The input to `indir` must be a directory where the first-level directories are the model names,
with JSON files from `spacy evaluate` in this file format: {task}_{dataset}.json
"""
results = []
for model_dir in indir.iterdir():
if model_dir.is_dir():
model_name = model_dir.name
for json_file in model_dir.glob("*.json"):
task, dataset = json_file.stem.split("_")
data = read_json(json_file)
results.append((model_name, task, dataset, data))

msg.info(f"Found {len(results)} results in {indir}")

msg.text("Parsing syntactic annotation results...")
syn_rows = []
for model_name, task, dataset, data in results:
if task == "dep":
row = {
"model": model_name,
"dataset": dataset,
"token_acc": data.get("tokenizer").get("token_f"),
"lemma_acc": data.get("trainable_lemmatizer").get("lemma_acc"),
"tag_acc": data.get("tagger").get("tag_acc"),
"pos_acc": data.get("morphologizer").get("pos_acc"),
"morph_acc": data.get("morphologizer").get("morph_acc"),
"dep_uas": data.get("parser").get("dep_uas"),
"dep_las": data.get("parser").get("dep_las"),
}
syn_rows.append(row)

syn_df = pd.DataFrame(syn_rows).sort_values(by="dataset").reset_index(drop=True)
print(syn_df.to_markdown(index=False))

msg.text("Parsing NER results...")
ner_rows = []
for model_name, task, dataset, data in results:
if task == "ner":
row = {
"model": model_name,
"dataset": dataset,
"ents_p": data.get("ner").get("ents_p"),
"ents_r": data.get("ner").get("ents_r"),
"ents_f": data.get("ner").get("ents_f"),
}
ner_rows.append(row)

ner_df = pd.DataFrame(ner_rows).sort_values(by="dataset").reset_index(drop=True)
print(ner_df.to_markdown(index=False))


def parse_syntactic_results(results: dict[str, Any]) -> dict[str, float]:
"""Get tokenizer, lemmatization, morph, and parsing evals"""
pass


def parse_ner_results(results: dict[str, Any]) -> dict[str, float]:
"""Get NER evals"""
pass


if __name__ == "__main__":
typer.run(report)
Loading