harryroger798 commited on
Commit
ede39dc
·
verified ·
1 Parent(s): ad55996

Fix Level 2 thresholds: remove word_count restrictions for better human text detection

Browse files
Files changed (1) hide show
  1. app.py +12 -12
app.py CHANGED
@@ -544,31 +544,31 @@ def predict(text: str) -> Dict[str, Any]:
544
  ai_prob = probs[0][1].item()
545
  label = LABELS[pred_class]
546
 
547
- # ===== CASUAL HUMAN TEXT CORRECTION =====
548
- # If RoBERTa says AI, check if Level 2 strongly indicates casual human text
549
  # Level 2 returns AI score (0.0 = definitely human, 1.0 = definitely AI)
550
- # AI text typically has Level 2 scores > 0.90, human text < 0.70
551
  if pred_class == 1: # RoBERTa says AI
552
  level2 = Level2_StatisticalFingerprinting()
553
  level2_score = level2.detect(text)
554
  word_count = len(text.split())
555
 
556
  # Override when Level 2 indicates human (score < 0.70)
557
- # AI text has scores > 0.90, so this won't trigger for AI
558
- if level2_score < 0.40:
559
- # Very strong casual human indicators - definitely human
560
  label = "Human-Written"
561
  human_prob = max(human_prob, 1 - level2_score)
562
  ai_prob = min(ai_prob, level2_score)
563
  confidence = human_prob
564
- elif level2_score < 0.60 and word_count < 35:
565
- # Strong casual indicators in short/medium text
566
  label = "Human-Written"
567
- human_prob = max(human_prob, 0.70)
568
- ai_prob = min(ai_prob, 0.30)
569
  confidence = human_prob
570
- elif level2_score < 0.70 and word_count < 20:
571
- # Moderate casual indicators in short text
572
  label = "Human-Written"
573
  human_prob = max(human_prob, 0.65)
574
  ai_prob = min(ai_prob, 0.35)
 
544
  ai_prob = probs[0][1].item()
545
  label = LABELS[pred_class]
546
 
547
+ # ===== HUMAN TEXT CORRECTION =====
548
+ # If RoBERTa says AI, check if Level 2 indicates human text
549
  # Level 2 returns AI score (0.0 = definitely human, 1.0 = definitely AI)
550
+ # AI text typically has Level 2 scores > 0.85, human text < 0.60
551
  if pred_class == 1: # RoBERTa says AI
552
  level2 = Level2_StatisticalFingerprinting()
553
  level2_score = level2.detect(text)
554
  word_count = len(text.split())
555
 
556
  # Override when Level 2 indicates human (score < 0.70)
557
+ # AI text has scores > 0.85, so this won't trigger for AI
558
+ if level2_score < 0.35:
559
+ # Very strong human indicators - definitely human
560
  label = "Human-Written"
561
  human_prob = max(human_prob, 1 - level2_score)
562
  ai_prob = min(ai_prob, level2_score)
563
  confidence = human_prob
564
+ elif level2_score < 0.55:
565
+ # Strong human indicators - likely human
566
  label = "Human-Written"
567
+ human_prob = max(human_prob, 0.75)
568
+ ai_prob = min(ai_prob, 0.25)
569
  confidence = human_prob
570
+ elif level2_score < 0.70:
571
+ # Moderate human indicators - probably human
572
  label = "Human-Written"
573
  human_prob = max(human_prob, 0.65)
574
  ai_prob = min(ai_prob, 0.35)