Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -428,18 +428,17 @@ def compute_abuse_score(matched_scores, sentiment):
|
|
428 |
if any(score > 0.8 for _, score, _ in matched_scores):
|
429 |
base_score *= 1.05 # Reduced
|
430 |
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
base_score *= 1.15
|
443 |
|
444 |
# Reduce minimum score and threshold for activation
|
445 |
if any(score > 0.9 for _, score, _ in matched_scores): # Higher threshold
|
|
|
428 |
if any(score > 0.8 for _, score, _ in matched_scores):
|
429 |
base_score *= 1.05 # Reduced
|
430 |
|
431 |
+
def get_sentiment_predictions(texts, sentiment_model, sentiment_tokenizer, batch_size=16):
|
432 |
+
predictions = []
|
433 |
+
for i in tqdm(range(0, len(texts), batch_size), desc="Predicting sentiment"):
|
434 |
+
batch = texts[i:i+batch_size]
|
435 |
+
inputs = sentiment_tokenizer(batch, return_tensors="pt", truncation=True, padding=True, max_length=128).to(device)
|
436 |
+
with torch.no_grad(): # Correct indentation
|
437 |
+
outputs = sentiment_model(**inputs) # Indent within 'with' block
|
438 |
+
logits = outputs.logits # Indent within 'with' block
|
439 |
+
predicted_classes = logits.argmax(dim=-1).tolist() # Indent within 'with' block
|
440 |
+
predictions.extend(predicted_classes) # Indent within 'with' block
|
441 |
+
return predictions
|
|
|
442 |
|
443 |
# Reduce minimum score and threshold for activation
|
444 |
if any(score > 0.9 for _, score, _ in matched_scores): # Higher threshold
|