Skip to content

Commit 5968f73

Browse files
authored
Merge pull request #171 from realpython/kylestratis-patch-2
Update sentiment_analyzer.py
2 parents 76bfbc2 + fd04e56 commit 5968f73

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

nlp-sentiment-analysis/sentiment_analyzer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ def evaluate_model(tokenizer, textcat, test_data: list) -> dict:
7979
true_negatives = 0
8080
false_negatives = 1e-8
8181
for i, review in enumerate(textcat.pipe(reviews)):
82-
true_label = labels[i]
82+
true_label = labels[i]["cats"]
8383
for predicted_label, score in review.cats.items():
8484
# Every cats dictionary includes both labels, you can get all
8585
# the info you need with just the pos label
8686
if predicted_label == "neg":
8787
continue
88-
if score >= 0.5 and true_label == "pos":
88+
if score >= 0.5 and true_label["pos"]:
8989
true_positives += 1
90-
elif score >= 0.5 and true_label == "neg":
90+
elif score >= 0.5 and true_label["neg"]:
9191
false_positives += 1
92-
elif score < 0.5 and true_label == "neg":
92+
elif score < 0.5 and true_label["neg"]:
9393
true_negatives += 1
94-
elif score < 0.5 and true_label == "pos":
94+
elif score < 0.5 and true_label["pos"]:
9595
false_negatives += 1
9696
precision = true_positives / (true_positives + false_positives)
9797
recall = true_positives / (true_positives + false_negatives)

0 commit comments

Comments
 (0)