SamanthaStorm commited on
Commit
bcfa072
·
verified ·
1 Parent(s): d11c93a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -29
app.py CHANGED
@@ -106,15 +106,16 @@ THRESHOLDS = {
106
  "nonabusive": 1.0
107
  }
108
 
 
109
  PATTERN_WEIGHTS = {
110
  "recovery": 0.7,
111
  "control": 1.4,
112
- "gaslighting": 1.50,
113
  "guilt tripping": 1.2,
114
  "dismissiveness": 0.9,
115
- "blame shifting": 0.8,
116
  "projection": 0.5,
117
- "insults": 1.4,
118
  "contradictory statements": 1.0,
119
  "obscure language": 0.9,
120
  "nonabusive": 0.0
@@ -331,50 +332,51 @@ def compute_abuse_score(matched_scores, sentiment):
331
  """Compute abuse score from matched patterns and sentiment"""
332
  try:
333
  if not matched_scores:
 
334
  return 0.0
335
 
 
336
  total_weight = sum(weight for _, _, weight in matched_scores)
337
  if total_weight == 0:
 
338
  return 0.0
339
 
 
340
  pattern_scores = [(label, score) for label, score, _ in matched_scores]
341
  sorted_scores = sorted(pattern_scores, key=lambda x: x[1], reverse=True)
 
342
 
 
343
  weighted_sum = sum(score * weight for _, score, weight in matched_scores)
344
  base_score = (weighted_sum / total_weight) * 100
345
-
346
- # Pattern combination multipliers
347
- if len(matched_scores) >= 3:
348
- base_score *= 1.2
349
-
350
- high_severity_patterns = {'gaslighting', 'control', 'blame shifting'}
351
- if any(label in high_severity_patterns for label, _, _ in matched_scores):
352
- base_score *= 1.15
353
-
354
- if any(score > 0.6 for _, score, _ in matched_scores):
355
- base_score *= 1.1
 
 
356
 
357
- high_scores = len([score for _, score, _ in matched_scores if score > 0.5])
358
- if high_scores >= 2:
359
- base_score *= 1.15
360
-
361
- # Apply sentiment modifiers
362
  if sentiment == "supportive":
363
- if any(label in high_severity_patterns for label, _, _ in matched_scores):
364
- base_score *= 0.9
365
- else:
366
- base_score *= 0.85
367
- elif sentiment == "undermining":
368
- base_score *= 1.15
369
-
370
- if any(score > 0.6 for _, score, _ in matched_scores):
371
- base_score = max(base_score, 65.0)
372
 
373
- return min(round(base_score, 1), 100.0)
 
 
 
374
  except Exception as e:
375
  logger.error(f"Error computing abuse score: {e}")
376
  return 0.0
377
 
 
378
  @spaces.GPU
379
  def analyze_single_message(text, thresholds):
380
  """Analyze a single message for abuse patterns"""
 
106
  "nonabusive": 1.0
107
  }
108
 
109
+
110
  PATTERN_WEIGHTS = {
111
  "recovery": 0.7,
112
  "control": 1.4,
113
+ "gaslighting": 1.3,
114
  "guilt tripping": 1.2,
115
  "dismissiveness": 0.9,
116
+ "blame shifting": 1.0, # Increased from 0.8
117
  "projection": 0.5,
118
+ "insults": 1.4, # Reduced from 2.1
119
  "contradictory statements": 1.0,
120
  "obscure language": 0.9,
121
  "nonabusive": 0.0
 
332
  """Compute abuse score from matched patterns and sentiment"""
333
  try:
334
  if not matched_scores:
335
+ logger.debug("No matched scores, returning 0")
336
  return 0.0
337
 
338
+ # Calculate weighted score
339
  total_weight = sum(weight for _, _, weight in matched_scores)
340
  if total_weight == 0:
341
+ logger.debug("Total weight is 0, returning 0")
342
  return 0.0
343
 
344
+ # Get highest pattern scores
345
  pattern_scores = [(label, score) for label, score, _ in matched_scores]
346
  sorted_scores = sorted(pattern_scores, key=lambda x: x[1], reverse=True)
347
+ logger.debug(f"Sorted pattern scores: {sorted_scores}")
348
 
349
+ # Base score calculation
350
  weighted_sum = sum(score * weight for _, score, weight in matched_scores)
351
  base_score = (weighted_sum / total_weight) * 100
352
+ logger.debug(f"Initial base score: {base_score:.1f}")
353
+
354
+ # Cap maximum score based on pattern severity
355
+ max_score = 85.0 # Set maximum possible score
356
+ if any(label in {'control', 'gaslighting'} for label, _, _ in matched_scores):
357
+ max_score = 90.0
358
+ logger.debug(f"Increased max score to {max_score} due to high severity patterns")
359
+
360
+ # Apply diminishing returns for multiple patterns
361
+ if len(matched_scores) > 1:
362
+ multiplier = 1 + (0.1 * (len(matched_scores) - 1))
363
+ base_score *= multiplier
364
+ logger.debug(f"Applied multiplier {multiplier:.2f} for {len(matched_scores)} patterns")
365
 
366
+ # Apply sentiment modifier
 
 
 
 
367
  if sentiment == "supportive":
368
+ base_score *= 0.85
369
+ logger.debug("Applied 15% reduction for supportive sentiment")
 
 
 
 
 
 
 
370
 
371
+ final_score = min(round(base_score, 1), max_score)
372
+ logger.debug(f"Final abuse score: {final_score}")
373
+ return final_score
374
+
375
  except Exception as e:
376
  logger.error(f"Error computing abuse score: {e}")
377
  return 0.0
378
 
379
+
380
  @spaces.GPU
381
  def analyze_single_message(text, thresholds):
382
  """Analyze a single message for abuse patterns"""