Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 (
|
| 51 |
-
sentiment_probs = F.softmax(sentiment_logits, dim=1)
|
| 52 |
-
|
| 53 |
-
|
| 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,
|
| 62 |
|
| 63 |
return {
|
| 64 |
-
"Sentiment":
|
| 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 |
|