Jaja-09 commited on
Commit
a5365c5
·
1 Parent(s): e186169

tweak(confidence): blend modified prob with chunk majority; floor when unanimous

Browse files
Files changed (1) hide show
  1. model_handler.py +17 -1
model_handler.py CHANGED
@@ -569,7 +569,23 @@ class AIDetectionModelHandler:
569
  modified_prob = (overall_prob * 0.7) + (chunk_avg_prob * 0.3)
570
 
571
  final_prediction = 'Human' if modified_prob < 0.5 else 'AI'
572
- confidence = abs(modified_prob - 0.5) * 2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573
 
574
  logger.info(f" → Pure {final_prediction} text")
575
  logger.info(f" → Original overall probability: {overall_prob:.3f}")
 
569
  modified_prob = (overall_prob * 0.7) + (chunk_avg_prob * 0.3)
570
 
571
  final_prediction = 'Human' if modified_prob < 0.5 else 'AI'
572
+ # Base confidence from modified probability (0..1)
573
+ base_confidence = abs(modified_prob - 0.5) * 2
574
+
575
+ # For short texts/few chunks, incorporate chunk-majority evidence to avoid
576
+ # under-confident results when the label is clear but probability is near 0.5.
577
+ if total_chunks > 0:
578
+ majority_ratio = max(human_chunks, ai_chunks) / total_chunks # e.g., 3/4 => 0.75
579
+ combined_confidence = max(
580
+ base_confidence,
581
+ 0.6 * majority_ratio + 0.4 * base_confidence
582
+ )
583
+ # If every chunk agrees, ensure a reasonable floor
584
+ if majority_ratio == 1.0 and total_chunks >= 3:
585
+ combined_confidence = max(combined_confidence, 0.85)
586
+ confidence = min(0.99, combined_confidence)
587
+ else:
588
+ confidence = base_confidence
589
 
590
  logger.info(f" → Pure {final_prediction} text")
591
  logger.info(f" → Original overall probability: {overall_prob:.3f}")