SamanthaStorm commited on
Commit
a3ecfe2
·
verified ·
1 Parent(s): 80e6ac9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
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
- # Sentiment modifier (more nuanced)
432
- if sentiment == "supportive":
433
- manipulative_patterns = {'guilt tripping', 'gaslighting', 'blame shifting', 'love bombing'}
434
- if any(label in manipulative_patterns for label, score, _ in matched_scores if score > 0.6): # Higher threshold
435
- base_score *= 0.95 # Smaller reduction for strongly manipulative "support"
436
- elif any(label in manipulative_patterns for label, score, _ in matched_scores if score > 0.4): # Moderate threshold
437
- base_score *= 0.9 # Moderate reduction for manipulative "support"
438
- else:
439
- base_score *= 0.8 # Larger reduction for genuine support
440
-
441
- elif sentiment == "undermining":
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