Spaces:
Sleeping
Sleeping
Update model.py
Browse files
model.py
CHANGED
|
@@ -18,3 +18,15 @@ class EmotionModel:
|
|
| 18 |
for i in range(len(probs)) if probs[i] > 0.3
|
| 19 |
}
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
for i in range(len(probs)) if probs[i] > 0.3
|
| 19 |
}
|
| 20 |
|
| 21 |
+
class SuicidalIntentModel:
|
| 22 |
+
def __init__(self):
|
| 23 |
+
self.model_name = "sentinet/suicidality"
|
| 24 |
+
self.tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 25 |
+
self.model = AutoModelForSequenceClassification.from_pretrained(self.model_name)
|
| 26 |
+
|
| 27 |
+
def predict(self, text):
|
| 28 |
+
inputs = self.tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
| 29 |
+
with torch.no_grad():
|
| 30 |
+
logits = self.model(**inputs).logits
|
| 31 |
+
probs = torch.nn.functional.softmax(logits, dim=1)
|
| 32 |
+
return float(probs[0][1]) # Probability of suicidal intent
|