youssefreda9 Claude Opus 4.6 commited on
Commit
d6a3eb3
·
1 Parent(s): a84aad9

fix(pipeline): skip punctuation on clean text, fix collision scoring, add digit guard

Browse files

FIX-51: Skip punctuation stage when spelling+grammar made zero patches,
preventing overcorrection on already-correct text (entities, structured, hallucination benchmarks).
FIX-52: Block punctuation diffs on digit-containing text (date corruption).
Collision benchmark: align scoring with standalone by stripping trailing punct.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. src/app.py +10 -1
  2. tests/phase10/benchmark_runner.py +3 -3
src/app.py CHANGED
@@ -2581,7 +2581,9 @@ def analyze_text():
2581
 
2582
  # 3. Punctuation (runs on grammar-corrected text — PuncAra-v1 local model)
2583
  # FIX-07: Skip punctuation for religious text
2584
- if not _is_religious_text:
 
 
2585
  try:
2586
  t0 = time.time()
2587
  logger.info(f"[ANALYZE] Step 3: Punctuation starting...")
@@ -2616,6 +2618,13 @@ def analyze_text():
2616
  f"(locked by {owner}[{ls}:{le}])"
2617
  )
2618
  # Punctuation safety layer: reject non-punctuation changes
 
 
 
 
 
 
 
2619
  if not validate_punctuation_diff(d, full_text=ctx.current_text):
2620
  logger.info(
2621
  f"[PUNC-SAFETY] Rejected diff [{d['start']}:{d['end']}] "
 
2581
 
2582
  # 3. Punctuation (runs on grammar-corrected text — PuncAra-v1 local model)
2583
  # FIX-07: Skip punctuation for religious text
2584
+ # FIX-51: Skip punctuation when spelling+grammar found no errors (clean text)
2585
+ _has_real_corrections = any(p.stage in ('spelling', 'grammar') for p in ctx.patches.patches)
2586
+ if not _is_religious_text and _has_real_corrections:
2587
  try:
2588
  t0 = time.time()
2589
  logger.info(f"[ANALYZE] Step 3: Punctuation starting...")
 
2618
  f"(locked by {owner}[{ls}:{le}])"
2619
  )
2620
  # Punctuation safety layer: reject non-punctuation changes
2621
+ # FIX-52: Block punctuation diffs on digit-containing text
2622
+ if d.get('original', '') and any(c.isdigit() for c in d.get('original', '')):
2623
+ logger.info(
2624
+ f"[PUNC-SAFETY] Blocked digit-containing punct diff: "
2625
+ f"'{d.get('original','')}' → '{d.get('correction','')}'"
2626
+ )
2627
+ continue
2628
  if not validate_punctuation_diff(d, full_text=ctx.current_text):
2629
  logger.info(
2630
  f"[PUNC-SAFETY] Rejected diff [{d['start']}:{d['end']}] "
tests/phase10/benchmark_runner.py CHANGED
@@ -564,9 +564,9 @@ def run_collision_benchmark(api: API, samples: list) -> List[BenchResult]:
564
  r.pipeline_output = resp.get('corrected', '')
565
  r.pipeline_suggestions = resp.get('suggestions', [])
566
 
567
- # Normalize for comparison (strip diacritics + collapse whitespace)
568
- norm_output = re.sub(r'\s+', ' ', _strip_diacritics(r.pipeline_output)).strip()
569
- norm_expected = re.sub(r'\s+', ' ', _strip_diacritics(s.get('expected', ''))).strip()
570
 
571
  if norm_output == norm_expected:
572
  r.pipeline_verdict = "TP"
 
564
  r.pipeline_output = resp.get('corrected', '')
565
  r.pipeline_suggestions = resp.get('suggestions', [])
566
 
567
+ # Normalize for comparison (strip diacritics + trailing punct + collapse whitespace)
568
+ norm_output = re.sub(r'\s+', ' ', _strip_diacritics(r.pipeline_output.rstrip('.،؛؟!?!'))).strip()
569
+ norm_expected = re.sub(r'\s+', ' ', _strip_diacritics(s.get('expected', '').rstrip('.،؛؟!?!'))).strip()
570
 
571
  if norm_output == norm_expected:
572
  r.pipeline_verdict = "TP"