From 981cb891949d3fed5c7a6d1873cba95d8a2f0f1d Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sat, 23 Feb 2019 12:45:41 +0100 Subject: [PATCH] Fix f-score calculation if zero --- examples/training/train_textcat.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/training/train_textcat.py b/examples/training/train_textcat.py index a81b7fbe5..7b55afe04 100644 --- a/examples/training/train_textcat.py +++ b/examples/training/train_textcat.py @@ -140,7 +140,10 @@ def evaluate(tokenizer, textcat, texts, cats): fn += 1 precision = tp / (tp + fp) recall = tp / (tp + fn) - f_score = 2 * (precision * recall) / (precision + recall) + if (precision+recall) == 0: + f_score = 0.0 + else: + f_score = 2 * (precision * recall) / (precision + recall) return {"textcat_p": precision, "textcat_r": recall, "textcat_f": f_score}