thushalya commited on
Commit
b286b42
1 Parent(s): f9f9f68

Add torch.nograd

Browse files
Files changed (1) hide show
  1. app.py +11 -10
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
- inputs = tokenizer(text, truncation=True, padding=True, return_tensors="pt")
155
- outputs = model(**inputs)
156
- predictions = outputs.logits.squeeze().detach().numpy()
157
-
158
- # Get raw logits
159
- logits = model(**inputs).logits
160
-
161
- # Apply sigmoid to squash between 0 and 1
162
- probabilities = torch.sigmoid(logits)
 
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