Skip to content

Commit

Permalink
Merge pull request #171 from realpython/kylestratis-patch-2
Browse files Browse the repository at this point in the history
Update sentiment_analyzer.py
  • Loading branch information
somacdivad authored Nov 18, 2020
2 parents 76bfbc2 + fd04e56 commit 5968f73
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions nlp-sentiment-analysis/sentiment_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ def evaluate_model(tokenizer, textcat, test_data: list) -> dict:
true_negatives = 0
false_negatives = 1e-8
for i, review in enumerate(textcat.pipe(reviews)):
true_label = labels[i]
true_label = labels[i]["cats"]
for predicted_label, score in review.cats.items():
# Every cats dictionary includes both labels, you can get all
# the info you need with just the pos label
if predicted_label == "neg":
continue
if score >= 0.5 and true_label == "pos":
if score >= 0.5 and true_label["pos"]:
true_positives += 1
elif score >= 0.5 and true_label == "neg":
elif score >= 0.5 and true_label["neg"]:
false_positives += 1
elif score < 0.5 and true_label == "neg":
elif score < 0.5 and true_label["neg"]:
true_negatives += 1
elif score < 0.5 and true_label == "pos":
elif score < 0.5 and true_label["pos"]:
false_negatives += 1
precision = true_positives / (true_positives + false_positives)
recall = true_positives / (true_positives + false_negatives)
Expand Down

0 comments on commit 5968f73

Please sign in to comment.