Jet-12138 commited on
Commit
36cb2a4
·
verified ·
1 Parent(s): 7beef84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -47,21 +47,24 @@ def analyse_comment(comment):
47
  sentiment_logits = outputs["sentiment_logits"]
48
  toxicity_logits = outputs["toxicity_logits"]
49
 
50
- # Process sentiment (single label classification)
51
- sentiment_probs = F.softmax(sentiment_logits, dim=1)
52
- sentiment_idx = torch.argmax(sentiment_probs, dim=1).item()
53
- sentiment_prediction = sentiment_labels[sentiment_idx]
54
-
 
 
 
55
  # Process toxicity (multi-label classification)
56
  toxicity_probs = torch.sigmoid(toxicity_logits).squeeze(0) # shape: (6,)
57
  toxicity_predictions = {}
58
 
59
  for idx, label in enumerate(toxicity_labels):
60
  prob = toxicity_probs[idx].item()
61
- toxicity_predictions[label] = round(prob, 2)
62
 
63
  return {
64
- "Sentiment": sentiment_prediction,
65
  "Toxicity Probabilities": toxicity_predictions
66
  }
67
 
 
47
  sentiment_logits = outputs["sentiment_logits"]
48
  toxicity_logits = outputs["toxicity_logits"]
49
 
50
+ # Process sentiment (multi-class classification)
51
+ sentiment_probs = F.softmax(sentiment_logits, dim=1).squeeze(0) # shape: (3,)
52
+ sentiment_predictions = {}
53
+
54
+ for idx, label in enumerate(sentiment_labels):
55
+ prob = sentiment_probs[idx].item()
56
+ sentiment_predictions[label] = round(prob, 4)
57
+
58
  # Process toxicity (multi-label classification)
59
  toxicity_probs = torch.sigmoid(toxicity_logits).squeeze(0) # shape: (6,)
60
  toxicity_predictions = {}
61
 
62
  for idx, label in enumerate(toxicity_labels):
63
  prob = toxicity_probs[idx].item()
64
+ toxicity_predictions[label] = round(prob, 4)
65
 
66
  return {
67
+ "Sentiment Probabilities": sentiment_predictions,
68
  "Toxicity Probabilities": toxicity_predictions
69
  }
70