SamanthaStorm commited on
Commit
16d3234
·
verified ·
1 Parent(s): 9611c30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -66,10 +66,23 @@ model_name = "SamanthaStorm/tether-multilabel-v4"
66
  model = AutoModelForSequenceClassification.from_pretrained(model_name).to(device)
67
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
68
 
69
- # sentiment model
70
- sentiment_model = AutoModelForSequenceClassification.from_pretrained("SamanthaStorm/tether-sentiment").to(device)
71
- sentiment_tokenizer = AutoTokenizer.from_pretrained("SamanthaStorm/tether-sentiment", use_fast=False)
72
- sentiment_model.eval()
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
 
75
  emotion_pipeline = hf_pipeline(
@@ -556,13 +569,21 @@ def analyze_single_message(text, thresholds):
556
  weight *= 1.5
557
  matched_scores.append((label, score, weight))
558
 
 
559
  # Get sentiment
560
  sent_inputs = sentiment_tokenizer(text, return_tensors="pt", truncation=True, padding=True)
561
  sent_inputs = {k: v.to(device) for k, v in sent_inputs.items()}
562
  with torch.no_grad():
563
  sent_logits = sentiment_model(**sent_inputs).logits[0]
564
- sent_probs = torch.softmax(sent_logits, dim=-1).cpu().numpy()
 
 
 
 
 
 
565
  sentiment = SENTIMENT_LABELS[int(np.argmax(sent_probs))]
 
566
 
567
  # Calculate abuse score
568
  abuse_score = compute_abuse_score(matched_scores, sentiment)
 
66
  model = AutoModelForSequenceClassification.from_pretrained(model_name).to(device)
67
  tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=False)
68
 
69
+ # sentiment model - add no_cache=True and force_download=True
70
+ sentiment_model = AutoModelForSequenceClassification.from_pretrained(
71
+ "SamanthaStorm/tether-sentiment",
72
+ no_cache=True,
73
+ force_download=True
74
+ ).to(device)
75
+ sentiment_tokenizer = AutoTokenizer.from_pretrained(
76
+ "SamanthaStorm/tether-sentiment",
77
+ use_fast=False,
78
+ no_cache=True,
79
+ force_download=True
80
+ )
81
+
82
+ # After loading the sentiment model
83
+ logger.debug(f"\nSentiment Model Config:")
84
+ logger.debug(f"Model name: {sentiment_model.config.name_or_path}")
85
+ logger.debug(f"Last modified: {sentiment_model.config._name_or_path}")
86
 
87
 
88
  emotion_pipeline = hf_pipeline(
 
569
  weight *= 1.5
570
  matched_scores.append((label, score, weight))
571
 
572
+ # In analyze_single_message, modify the sentiment section:
573
  # Get sentiment
574
  sent_inputs = sentiment_tokenizer(text, return_tensors="pt", truncation=True, padding=True)
575
  sent_inputs = {k: v.to(device) for k, v in sent_inputs.items()}
576
  with torch.no_grad():
577
  sent_logits = sentiment_model(**sent_inputs).logits[0]
578
+ sent_probs = torch.softmax(sent_logits, dim=-1).cpu().numpy()
579
+
580
+ # Add detailed logging
581
+ logger.debug("\n🎭 SENTIMENT ANALYSIS DETAILS")
582
+ logger.debug(f"Raw logits: {sent_logits}")
583
+ logger.debug(f"Probabilities: undermining={sent_probs[0]:.3f}, supportive={sent_probs[1]:.3f}")
584
+
585
  sentiment = SENTIMENT_LABELS[int(np.argmax(sent_probs))]
586
+ logger.debug(f"Selected sentiment: {sentiment}")
587
 
588
  # Calculate abuse score
589
  abuse_score = compute_abuse_score(matched_scores, sentiment)