thushalya
commited on
Commit
•
b286b42
1
Parent(s):
f9f9f68
Add torch.nograd
Browse files
app.py
CHANGED
@@ -150,16 +150,17 @@ def personality_detection(text, threshold=0.05, endpoint= 1.0):
|
|
150 |
print(PERSONALITY_TOKEN)
|
151 |
tokenizer = AutoTokenizer.from_pretrained ("Nasserelsaman/microsoft-finetuned-personality",token=PERSONALITY_TOKEN)
|
152 |
model = AutoModelForSequenceClassification.from_pretrained ("Nasserelsaman/microsoft-finetuned-personality",token=PERSONALITY_TOKEN)
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
163 |
|
164 |
# # Set values less than the threshold to 0.05
|
165 |
# predictions[predictions < threshold] = 0.05
|
|
|
150 |
print(PERSONALITY_TOKEN)
|
151 |
tokenizer = AutoTokenizer.from_pretrained ("Nasserelsaman/microsoft-finetuned-personality",token=PERSONALITY_TOKEN)
|
152 |
model = AutoModelForSequenceClassification.from_pretrained ("Nasserelsaman/microsoft-finetuned-personality",token=PERSONALITY_TOKEN)
|
153 |
+
|
154 |
+
with torch.no_grad():
|
155 |
+
inputs = tokenizer(text, truncation=True, padding=True, return_tensors="pt")
|
156 |
+
outputs = model(**inputs)
|
157 |
+
predictions = outputs.logits.squeeze().detach().numpy()
|
158 |
+
|
159 |
+
# Get raw logits
|
160 |
+
logits = model(**inputs).logits
|
161 |
+
|
162 |
+
# Apply sigmoid to squash between 0 and 1
|
163 |
+
probabilities = torch.sigmoid(logits)
|
164 |
|
165 |
# # Set values less than the threshold to 0.05
|
166 |
# predictions[predictions < threshold] = 0.05
|