Spaces:
Sleeping
Sleeping
Fix Level 2 thresholds: remove word_count restrictions for better human text detection
Browse files
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 |
-
# =====
|
| 548 |
-
# If RoBERTa says AI, check if Level 2
|
| 549 |
# Level 2 returns AI score (0.0 = definitely human, 1.0 = definitely AI)
|
| 550 |
-
# AI text typically has Level 2 scores > 0.
|
| 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.
|
| 558 |
-
if level2_score < 0.
|
| 559 |
-
# Very strong
|
| 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.
|
| 565 |
-
# Strong
|
| 566 |
label = "Human-Written"
|
| 567 |
-
human_prob = max(human_prob, 0.
|
| 568 |
-
ai_prob = min(ai_prob, 0.
|
| 569 |
confidence = human_prob
|
| 570 |
-
elif level2_score < 0.70
|
| 571 |
-
# Moderate
|
| 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)
|