Skip to content

Commit

Permalink
fix: evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
severinsimmler committed Mar 15, 2022
1 parent 53fce99 commit 6787b2f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions chaine/optimization/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ def evaluate_predictions(true: list[list[str]], pred: list[list[str]]) -> dict[s
true_labels = [l.removeprefix("B-").removeprefix("I-") for l in true_labels]
predicted_labels = [l.removeprefix("B-").removeprefix("I-") for l in predicted_labels]

if len(true_labels) != len(predicted_labels):
raise ValueError(f"Different lengths: '{true_labels}' vs. '{predicted_labels}'")

for true_label, predicted_label in zip(true_labels, predicted_labels):
if true_label == "O" and true_label == predicted_label:
counts["tn"] += 1
elif true_label == "O" and true_label != predicted_label:
counts["fp"] += 1
elif true_label != "O" and true_label == predicted_label:
if true_label != "O" and predicted_label == true_label:
counts["tp"] += 1
elif true_label != "O" and predicted_label == "O":
counts["fn"] += 1
elif true_label != "O" and true_label != predicted_label:
if predicted_label != "O" and predicted_label != true_label:
counts["fp"] += 1
if true_label == "O" and predicted_label == "O":
counts["tn"] += 1
if true_label != "O" and predicted_label == "O":
counts["fn"] += 1

# calculate precision, recall and f1 score
return {
Expand Down

0 comments on commit 6787b2f

Please sign in to comment.