pstjohn commited on
Commit
b66f84b
·
verified ·
1 Parent(s): c4121f2

Document relaxed explicit-answer scoring and seven-aspect benchmark mean

Browse files

Replace prose letter harvesting with the pinned campaign parser. Document ambiguous answers, completion status, panel selection, and strict/relaxed reporting. Verified 23 parser cases and 700 saved responses in the pinned driver image.

Files changed (1) hide show
  1. README.md +213 -30
README.md CHANGED
@@ -311,8 +311,8 @@ def parse_boxed_answer(final_answer):
311
  Use the same single-choice exact match and localization option-set micro-F1
312
  under this protocol. Report the prompt version, answer parser, token budget
313
  and malformed-answer rate. Keep historical plain-letter scores identified as
314
- such; their answer protocol differs. The illustrative scoring loop below uses
315
- plain-letter final answers. Never apply its letter extraction to reasoning prose.
316
 
317
  Trace-envelope checks, such as the native Lightning newline and closing-tag
318
  contract, belong to training diagnostics and GRPO formatting rewards. Report
@@ -320,42 +320,225 @@ these separately from benchmark answer scores. Missing, hidden or separately
320
  returned reasoning must not invalidate an otherwise correct benchmark answer.
321
  This documentation does not modify the frozen `test.parquet` or its SHA-256.
322
 
323
- ### Scoring
324
-
325
- Report exact-match accuracy separately for each of the six single-choice aspects. For localization, parse the predicted option set and report option-set micro-F1 across all 500 questions.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
326
 
327
  ```python
328
  import re
329
- from collections import defaultdict
330
-
331
- LETTERS = "ABCDEFGHIJ"
332
-
333
- def parse_prediction(text):
334
- found = re.findall(r"(?<![A-Z])[A-J](?![A-Z])", text.upper())
335
- return sorted({LETTERS.index(letter) for letter in found})
336
-
337
- def score(rows, prediction_texts):
338
- exact = defaultdict(list)
339
- tp = fp = fn = 0
340
- for row, text in zip(rows, prediction_texts, strict=True):
341
- predicted = set(parse_prediction(text))
342
- gold = set(row["answer_indices"])
343
- if row["aspect"] == "localization":
344
- tp += len(predicted & gold)
345
- fp += len(predicted - gold)
346
- fn += len(gold - predicted)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  else:
348
- exact[row["aspect"]].append(predicted == gold)
 
 
 
 
 
 
 
 
349
  return {
350
- "accuracy_by_aspect": {
351
- aspect: sum(values) / len(values)
352
- for aspect, values in sorted(exact.items())
353
- },
354
- "localization_micro_f1": 2 * tp / (2 * tp + fp + fn),
 
355
  }
 
356
  ```
357
 
358
- Prediction parsing should be fixed before evaluation. Do not use gold fields or provenance to repair model outputs. Preserve the frozen row order and IDs when reporting per-example results.
 
 
 
 
 
 
 
359
 
360
  ## References
361
 
 
311
  Use the same single-choice exact match and localization option-set micro-F1
312
  under this protocol. Report the prompt version, answer parser, token budget
313
  and malformed-answer rate. Keep historical plain-letter scores identified as
314
+ such; their answer protocol differs. The relaxed scoring implementation below accepts explicit answers accompanied
315
+ by explanations. Never concatenate separate reasoning into scored content.
316
 
317
  Trace-envelope checks, such as the native Lightning newline and closing-tag
318
  contract, belong to training diagnostics and GRPO formatting rewards. Report
 
320
  returned reasoning must not invalidate an otherwise correct benchmark answer.
321
  This documentation does not modify the frozen `test.parquet` or its SHA-256.
322
 
323
+ ### Scoring: relaxed explicit-answer extraction
324
+
325
+ The current relaxed scorer accepts explanatory assistant text when it contains
326
+ an explicit, unambiguous answer. It uses only the final assistant `content` and
327
+ presented choices; separate thinking, reasoning summaries, gold labels and
328
+ provenance are never inputs to answer extraction. This is deterministic parsing,
329
+ not an LLM judge or semantic answer matching.
330
+
331
+ The parser first retains answers accepted by the original strict parser. If that
332
+ fails, it tries consistent boxed selections, answer-labelled lines, then an
333
+ explicit leading, bolded or terminal selection. Full choice text is accepted
334
+ only when it matches exactly one presented choice, ignoring case, presentation
335
+ markup and a trailing period. It does not harvest option letters from prose or
336
+ accept a copied choice list as an answer. At the selected extraction priority,
337
+ conflicting selections, duplicates, alternatives such as “A or C”, and multiple
338
+ letters for a single-choice question score as an empty prediction.
339
+
340
+ Examples:
341
+
342
+ | Assistant content | Question type | Parsed selection |
343
+ | --- | --- | --- |
344
+ | `Final answer: C. Because A and B are distractors.` | single choice | C |
345
+ | `**C) siRNA processing**` | single choice | C |
346
+ | `Answer: A and C — both compartments.` | multi-select | A, C |
347
+ | `Analysis mentions A and B.` followed by `The answer is C.` | single choice | C |
348
+ | `Answer: A or C` | either | empty |
349
+ | `Answer: A, A` | either | empty |
350
+ | `Answer: A, C` | single choice | empty |
351
+ | `Answer: A` followed by `Answer: C` | either | empty |
352
+
353
+ For the six single-choice aspects, report exact-match accuracy. For localization,
354
+ aggregate true positives, false positives and false negatives across questions
355
+ and report option-set micro-F1, `2 TP / (2 TP + FP + FN)`. The headline score is
356
+ **the unweighted mean of these seven aspect metrics**, not pooled question
357
+ accuracy. An empty selection is incorrect for single-choice questions and adds
358
+ all gold localization options to false negatives.
359
+
360
+ The API completion status must be normalized to `finish_reason="stop"` for a
361
+ completed answer. Any other status, including token-limit termination, scores
362
+ as empty even if an early answer appears in the response. Missing responses
363
+ make a run incomplete; do not silently omit them or report a partial run as a
364
+ complete benchmark. Transport failures may be retried with the same policy;
365
+ completed or length-capped answers are not resampled to improve the score.
366
+
367
+ The implementation below is the current campaign parser and scoring policy.
368
+ It supports both the full test split and a published reviewed panel, provided
369
+ all seven aspects are represented. Select the 350-question panel by the IDs in
370
+ `subsets/350.json`; it contains 50 questions per aspect. The panel in the
371
+ backfilled 3,500-row release is identical to the reviewed-v2 panel.
372
 
373
  ```python
374
  import re
375
+ from collections import Counter
376
+
377
+ def final_options(content: str, multi_select: bool) -> set[str]:
378
+ """Parse one boxed final answer or an answer-only A–J list, never reasoning.
379
+
380
+ Extra boxes, malformed lists, duplicate options and missing answers score as
381
+ empty predictions. A single-choice response containing multiple options also
382
+ scores empty. Parsing is fixed independently of gold labels.
383
+ """
384
+ boxes = re.findall(r'\\boxed\{([^{}]*)\}', content)
385
+ if len(boxes) > 1:
386
+ return set()
387
+ answer = boxes[0] if boxes else content.strip()
388
+ if not re.fullmatch(r'\s*[A-J](?:\s*,\s*[A-J])*\s*', answer):
389
+ return set()
390
+ letters = [value.strip() for value in answer.split(',')]
391
+ if len(set(letters)) != len(letters) or (not multi_select and len(letters) != 1):
392
+ return set()
393
+ return set(letters)
394
+
395
+
396
+ def plain(text):
397
+ """Remove presentation markup while retaining option letters and prose."""
398
+ return re.sub(r'[*`]', '', text).strip().lstrip('#').strip()
399
+
400
+
401
+ def selection(text, multi_select):
402
+ """Read an explicit initial letter list without harvesting prose letters.
403
+
404
+ Accept commas, semicolons, slashes, ampersands and 'and'. Reject alternatives
405
+ expressed with 'or', duplicate letters and multiple single-choice selections.
406
+ The suffix may contain the answer text or an explanation.
407
+ """
408
+ text = plain(text)
409
+ match = re.match(r'^\(?([A-J])\b((?:\s*(?:,|;|/|&|\band\b)\s*[A-J]\b)*)', text)
410
+ if not match:
411
+ return None
412
+ suffix = text[match.end():]
413
+ if re.match(r'^\s*(?:or\b|(?:,|;|/|&)\s*(?:or\b|[A-J]\b))', suffix):
414
+ return None
415
+ # A letter must be separated from prose; an initial 'A protein ...' is not
416
+ # an answer selection. Parentheses, punctuation or a line break are explicit.
417
+ if suffix and not re.match(r'^\s*(?:[().,:;\-–—]|$)', suffix):
418
+ return None
419
+ letters = [match.group(1), *re.findall(r'\b[A-J]\b', match.group(2))]
420
+ if len(set(letters)) != len(letters) or (not multi_select and len(letters) != 1):
421
+ return None
422
+ return set(letters)
423
+
424
+
425
+ def explicit_answer(content, multi_select, choices, original_parser):
426
+ """Return a selection plus extraction evidence, or leave ambiguity ungraded.
427
+
428
+ Priority is original valid answer, consistent boxes, explicit answer-labelled
429
+ lines, then a leading selection. Named-choice matching requires a complete
430
+ choice text and uniqueness. Copied choice lists are not treated as selections.
431
+ """
432
+ original = original_parser(content, multi_select)
433
+ if original:
434
+ return original, 'original_valid'
435
+ boxes = re.findall(r'\\boxed\{([^{}]*)\}', content)
436
+ if boxes:
437
+ selected = [selection(box, multi_select) for box in boxes]
438
+ if all(selected) and len({tuple(sorted(s)) for s in selected}) == 1:
439
+ return selected[0], 'explicit_box'
440
+ return set(), 'ambiguous_or_invalid_box'
441
+ raw_lines = [line.strip() for line in content.splitlines() if plain(line)]
442
+ lines = [plain(line) for line in raw_lines]
443
+ if not lines:
444
+ return set(), 'empty'
445
+ labelled = []
446
+ for index, line in enumerate(lines):
447
+ if re.fullmatch(r'(?:final\s+|correct\s+)?answer\s*[:=]?', line, re.I):
448
+ if index+1 < len(lines):
449
+ labelled.append(lines[index+1])
450
+ continue
451
+ match = re.match(r'^(?:(?:therefore|thus|so)[,:]?\s*)?(?:the\s+)?(?:final\s+|correct\s+)?answer(?:\s+is)?\s*[:=\-]?\s+(.+)$', line, re.I)
452
+ if not match:
453
+ match = re.match(r'^(?:final\s+|correct\s+)?answer\s*[:=]\s*(.+)$', line, re.I)
454
+ if match:
455
+ labelled.append(match.group(1))
456
+ candidates = labelled or [lines[0]]
457
+ if not labelled and selection(lines[0], multi_select) is None:
458
+ # A separately bolded answer line is an explicit selection even when it
459
+ # follows an analysis paragraph. Multiple different selections conflict.
460
+ bold_selections = [line for raw, line in zip(raw_lines, lines)
461
+ if raw.startswith('**') and selection(line, multi_select)]
462
+ if bold_selections:
463
+ candidates = bold_selections
464
+ elif selection(lines[-1], multi_select):
465
+ # Some models put an unformatted final selection after explanatory
466
+ # paragraphs. A terminal selection must not merely end a choice list.
467
+ option_lines = [line for line in lines if re.match(r'^[A-J][).]\s', line)]
468
+ if len(option_lines) <= 1 or (re.match(r'^[A-J][).]\s*Correct\b', lines[-1], re.I)
469
+ and all(re.match(r'^[A-J][).]\s*Incorrect\b', line, re.I)
470
+ for line in option_lines[:-1])):
471
+ candidates = [lines[-1]]
472
+ parsed = []
473
+ for candidate in candidates:
474
+ result = selection(candidate, multi_select)
475
+ if result is None:
476
+ named = [chr(65+i) for i, choice in enumerate(choices)
477
+ if plain(candidate).casefold().rstrip('.') == plain(choice).casefold().rstrip('.')]
478
+ result = set(named) if len(named) == 1 else None
479
+ parsed.append(result)
480
+ if not all(parsed) or len({tuple(sorted(s)) for s in parsed}) != 1:
481
+ return set(), 'unresolved_or_conflicting_answer'
482
+ if not labelled and candidates == [lines[0]] and sum(bool(re.match(r'^[A-J][).]\s', line)) for line in lines) > 1:
483
+ return set(), 'unselected_choice_list'
484
+ return parsed[0], 'labelled_answer' if labelled else 'leading_answer'
485
+
486
+
487
+ def score(rows, predictions):
488
+ """Score every row by ID using explicit answers and completed responses.
489
+
490
+ predictions[id] must contain content and a normalized finish_reason.
491
+ Missing IDs raise KeyError rather than disappearing from the denominator.
492
+ """
493
+ counts, correct = Counter(), Counter()
494
+ tp = fp = fn = invalid = nonstop = 0
495
+ extraction = []
496
+ for row in rows:
497
+ prediction = predictions[row["id"]]
498
+ selected, rule = explicit_answer(
499
+ prediction["content"], row["aspect"] == "localization",
500
+ row["choices"], final_options,
501
+ )
502
+ if prediction["finish_reason"] != "stop":
503
+ selected, rule = set(), "nonstop_excluded"
504
+ nonstop += 1
505
+ gold = set(row["answer_letters"])
506
+ aspect = row["aspect"]
507
+ counts[aspect] += 1
508
+ invalid += not selected
509
+ if aspect == "localization":
510
+ tp += len(selected & gold)
511
+ fp += len(selected - gold)
512
+ fn += len(gold - selected)
513
  else:
514
+ correct[aspect] += selected == gold
515
+ extraction.append({"id": row["id"], "selected": sorted(selected), "rule": rule})
516
+ expected = {"biological_process", "domains", "family", "function",
517
+ "localization", "molecular_activity", "pathways"}
518
+ if set(counts) != expected:
519
+ raise ValueError("All seven aspects are required for comparison")
520
+ metrics = {aspect: correct[aspect] / counts[aspect]
521
+ for aspect in sorted(expected - {"localization"})}
522
+ metrics["localization"] = 2 * tp / (2 * tp + fp + fn)
523
  return {
524
+ "metrics": metrics,
525
+ "mean_seven_aspects": sum(metrics.values()) / 7,
526
+ "counts": dict(counts),
527
+ "invalid_answers": invalid,
528
+ "length_or_other_nonstop_answers": nonstop,
529
+ "extraction": extraction,
530
  }
531
+
532
  ```
533
 
534
+ Fix the parser before evaluation and use it identically for every model. Record
535
+ the dataset revision, selected subset, complete prompt, output ceiling, reasoning
536
+ settings, provider/model identity, finish-status normalization, parser version,
537
+ and invalid/capped counts. Keep historical strict scores labelled separately;
538
+ relaxed scoring changes answer extraction, not the underlying metric or labels.
539
+
540
+ Parser source SHA-256 (the `plain`, `selection`, and `explicit_answer` module):
541
+ `fbbf35373d71a8f67df5458fb10b2370e9ba3e589eec2adcec3c86cd4a98351a`.
542
 
543
  ## References
544