Skip to content
Snippets Groups Projects

add more info on output and reformat in md

Merged Christopher Kermorvant requested to merge output into master
5 files
+ 77
22
Compare changes
  • Side-by-side
  • Inline
Files
5
+ 22
11
@@ -10,6 +10,7 @@ import re
import editdistance
import edlib
import termtables as tt
THRESHOLD = 0.30
NOT_ENTITY_TAG = "O"
@@ -22,7 +23,7 @@ def parse_bio(path: str) -> dict:
Output format : { "words": str, "tags": list; "entity_count" : { tag : int} }
"""
assert os.path.exists(path)
assert os.path.exists(path), f"Error: Input file {path} does not exist"
words = []
tags = []
@@ -269,9 +270,12 @@ def compute_scores(
else 2 * (prec * rec) / (prec + rec)
)
scores[tag]["predicted"] = nb_predict
scores[tag]["matched"] = nb_match
scores[tag]["P"] = prec
scores[tag]["R"] = rec
scores[tag]["F1"] = f1
scores[tag]["Support"] = nb_annot
return scores
@@ -281,18 +285,25 @@ def print_results(scores: dict):
None values are kept to indicate the absence of a certain tag in either annotation or prediction.
"""
logging.info("-- Results --")
header = ["tag", "predicted", "matched", "Precision", "Recall", "F1", "Support"]
results = []
for tag in sorted(scores.keys())[::-1]:
prec = None if scores[tag]["P"] is None else round(scores[tag]["P"], 3)
rec = None if scores[tag]["R"] is None else round(scores[tag]["R"], 3)
f1 = None if scores[tag]["F1"] is None else round(scores[tag]["F1"], 3)
prec = None if scores[tag]["P"] is None else round(scores[tag]["P"], 2)
rec = None if scores[tag]["R"] is None else round(scores[tag]["R"], 2)
f1 = None if scores[tag]["F1"] is None else round(scores[tag]["F1"], 2)
logging.info(f"{tag} :")
logging.info(f"P = {prec}")
logging.info(f"R = {rec}")
logging.info(f"F1 = {f1}")
results.append(
[
tag,
scores[tag]["predicted"],
scores[tag]["matched"],
prec,
rec,
f1,
scores[tag]["Support"],
]
)
tt.print(results, header, style=tt.styles.markdown)
def run(annotation: str, prediction: str) -> dict:
Loading