Reja1 Claude Sonnet 4.6 commited on
Commit
dec6257
·
1 Parent(s): 6552cc2

fix: show partial-credit answers as yellow ~ in progress bar, not red incorrect

Browse files
src/benchmark_runner.py CHANGED
@@ -429,7 +429,7 @@ def process_question(
429
  def log_question_result(result_data: Dict[str, Any], prefix: str = "") -> str:
430
  """Logs a color-coded result for a single question.
431
 
432
- Returns a category string: 'correct', 'incorrect', 'skipped', 'parse_fail', or 'api_fail'.
433
  """
434
  question_id = result_data["question_id"]
435
  log_message_prefix = f"{prefix}Question {question_id}:"
@@ -451,6 +451,7 @@ def log_question_result(result_data: Dict[str, Any], prefix: str = "") -> str:
451
  evaluation_status_value = result_data.get("evaluation_status")
452
 
453
  is_considered_correct = False
 
454
  log_display_status = "N/A"
455
  status_check_string = ""
456
 
@@ -461,8 +462,10 @@ def log_question_result(result_data: Dict[str, Any], prefix: str = "") -> str:
461
  elif isinstance(evaluation_status_value, str):
462
  log_display_status = evaluation_status_value
463
  status_check_string = evaluation_status_value.strip().upper()
464
- if "CORRECT" in status_check_string:
465
  is_considered_correct = True
 
 
466
  elif evaluation_status_value is None:
467
  log_display_status = "None"
468
  status_check_string = "NONE_STATUS"
@@ -475,6 +478,9 @@ def log_question_result(result_data: Dict[str, Any], prefix: str = "") -> str:
475
  if is_considered_correct:
476
  print(f"{GREEN}{log_message_prefix} Correct - Marks: {marks_awarded}, Status: {log_display_status} {log_message_suffix}{RESET}")
477
  return "correct"
 
 
 
478
  elif status_check_string in known_eval_skip_statuses:
479
  print(f"{YELLOW}{log_message_prefix} Skipped by Eval - Marks: {marks_awarded}, Status: {log_display_status} {log_message_suffix}{RESET}")
480
  return "skipped"
@@ -852,6 +858,7 @@ def run_benchmark(
852
 
853
  # Counters for tqdm postfix
854
  initial_correct_count = 0
 
855
  initial_incorrect_count = 0
856
  initial_skipped_count = 0
857
  initial_parse_fail_count = 0
@@ -876,6 +883,8 @@ def run_benchmark(
876
 
877
  if category == "correct":
878
  initial_correct_count += 1
 
 
879
  elif category == "incorrect":
880
  initial_incorrect_count += 1
881
  elif category == "skipped":
@@ -884,7 +893,7 @@ def run_benchmark(
884
  initial_parse_fail_count += 1
885
  elif category == "api_fail":
886
  initial_api_fail_count += 1
887
- pbar_initial.set_postfix_str(f"✓:{initial_correct_count} ✗:{initial_incorrect_count} S:{initial_skipped_count} P!:{initial_parse_fail_count} A!:{initial_api_fail_count}")
888
 
889
  pbar_initial.close()
890
 
@@ -893,6 +902,7 @@ def run_benchmark(
893
  logging.info(f"--- Retrying {len(failed_questions_data)} questions with initial API failures for model: {model_id} ---")
894
 
895
  retry_correct_count = 0
 
896
  retry_incorrect_count = 0
897
  retry_skipped_count = 0
898
  retry_parse_fail_count = 0
@@ -938,6 +948,8 @@ def run_benchmark(
938
 
939
  if category == "correct":
940
  retry_correct_count += 1
 
 
941
  elif category == "incorrect":
942
  retry_incorrect_count += 1
943
  elif category == "skipped":
@@ -946,7 +958,7 @@ def run_benchmark(
946
  retry_parse_fail_count += 1
947
  elif category == "api_fail":
948
  retry_api_fail_count += 1
949
- pbar_retry.set_postfix_str(f"✓:{retry_correct_count} ✗:{retry_incorrect_count} S:{retry_skipped_count} P!:{retry_parse_fail_count} A!:{retry_api_fail_count}")
950
  pbar_retry.close()
951
 
952
  # --- Final Evaluation for the current model ---
 
429
  def log_question_result(result_data: Dict[str, Any], prefix: str = "") -> str:
430
  """Logs a color-coded result for a single question.
431
 
432
+ Returns a category string: 'correct', 'partial', 'incorrect', 'skipped', 'parse_fail', or 'api_fail'.
433
  """
434
  question_id = result_data["question_id"]
435
  log_message_prefix = f"{prefix}Question {question_id}:"
 
451
  evaluation_status_value = result_data.get("evaluation_status")
452
 
453
  is_considered_correct = False
454
+ is_partial = False
455
  log_display_status = "N/A"
456
  status_check_string = ""
457
 
 
462
  elif isinstance(evaluation_status_value, str):
463
  log_display_status = evaluation_status_value
464
  status_check_string = evaluation_status_value.strip().upper()
465
+ if status_check_string.startswith("CORRECT"):
466
  is_considered_correct = True
467
+ elif status_check_string.startswith("PARTIAL_"):
468
+ is_partial = True
469
  elif evaluation_status_value is None:
470
  log_display_status = "None"
471
  status_check_string = "NONE_STATUS"
 
478
  if is_considered_correct:
479
  print(f"{GREEN}{log_message_prefix} Correct - Marks: {marks_awarded}, Status: {log_display_status} {log_message_suffix}{RESET}")
480
  return "correct"
481
+ elif is_partial:
482
+ print(f"{YELLOW}{log_message_prefix} Partial - Marks: {marks_awarded}, Status: {log_display_status} {log_message_suffix}{RESET}")
483
+ return "partial"
484
  elif status_check_string in known_eval_skip_statuses:
485
  print(f"{YELLOW}{log_message_prefix} Skipped by Eval - Marks: {marks_awarded}, Status: {log_display_status} {log_message_suffix}{RESET}")
486
  return "skipped"
 
858
 
859
  # Counters for tqdm postfix
860
  initial_correct_count = 0
861
+ initial_partial_count = 0
862
  initial_incorrect_count = 0
863
  initial_skipped_count = 0
864
  initial_parse_fail_count = 0
 
883
 
884
  if category == "correct":
885
  initial_correct_count += 1
886
+ elif category == "partial":
887
+ initial_partial_count += 1
888
  elif category == "incorrect":
889
  initial_incorrect_count += 1
890
  elif category == "skipped":
 
893
  initial_parse_fail_count += 1
894
  elif category == "api_fail":
895
  initial_api_fail_count += 1
896
+ pbar_initial.set_postfix_str(f"✓:{initial_correct_count} ~:{initial_partial_count} ✗:{initial_incorrect_count} S:{initial_skipped_count} P!:{initial_parse_fail_count} A!:{initial_api_fail_count}")
897
 
898
  pbar_initial.close()
899
 
 
902
  logging.info(f"--- Retrying {len(failed_questions_data)} questions with initial API failures for model: {model_id} ---")
903
 
904
  retry_correct_count = 0
905
+ retry_partial_count = 0
906
  retry_incorrect_count = 0
907
  retry_skipped_count = 0
908
  retry_parse_fail_count = 0
 
948
 
949
  if category == "correct":
950
  retry_correct_count += 1
951
+ elif category == "partial":
952
+ retry_partial_count += 1
953
  elif category == "incorrect":
954
  retry_incorrect_count += 1
955
  elif category == "skipped":
 
958
  retry_parse_fail_count += 1
959
  elif category == "api_fail":
960
  retry_api_fail_count += 1
961
+ pbar_retry.set_postfix_str(f"✓:{retry_correct_count} ~:{retry_partial_count} ✗:{retry_incorrect_count} S:{retry_skipped_count} P!:{retry_parse_fail_count} A!:{retry_api_fail_count}")
962
  pbar_retry.close()
963
 
964
  # --- Final Evaluation for the current model ---
tests/test_benchmark_runner.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Tests for src/benchmark_runner.py — pure functions only."""
2
+
3
+ import sys, os
4
+ sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src'))
5
+
6
+ import pytest
7
+ from benchmark_runner import log_question_result
8
+
9
+
10
+ def _result(evaluation_status, marks_awarded, api_ok=True, parse_ok=True, pred=["A"]):
11
+ return {
12
+ "question_id": "TEST001",
13
+ "api_call_successful": api_ok,
14
+ "parse_successful": parse_ok,
15
+ "predicted_answer": pred,
16
+ "marks_awarded": marks_awarded,
17
+ "evaluation_status": evaluation_status,
18
+ "attempt": 1,
19
+ }
20
+
21
+
22
+ def test_correct_returns_correct():
23
+ assert log_question_result(_result("correct", 4)) == "correct"
24
+
25
+
26
+ def test_incorrect_returns_incorrect():
27
+ assert log_question_result(_result("incorrect", -1)) == "incorrect"
28
+
29
+
30
+ def test_partial_3_of_4_returns_partial():
31
+ assert log_question_result(_result("partial_3_of_4", 3)) == "partial"
32
+
33
+
34
+ def test_partial_2_of_3_plus_returns_partial():
35
+ assert log_question_result(_result("partial_2_of_3_plus", 2)) == "partial"
36
+
37
+
38
+ def test_partial_1_of_2_plus_returns_partial():
39
+ assert log_question_result(_result("partial_1_of_2_plus", 1)) == "partial"
40
+
41
+
42
+ def test_skip_returns_skipped():
43
+ assert log_question_result(_result("skipped", 0, pred="SKIP")) == "skipped"
44
+
45
+
46
+ def test_api_fail_returns_api_fail():
47
+ assert log_question_result(_result("failure_api_or_parse", 0, api_ok=False, parse_ok=False, pred=None)) == "api_fail"
48
+
49
+
50
+ def test_parse_fail_returns_parse_fail():
51
+ r = _result("failure_api_or_parse", 0, api_ok=True, parse_ok=False, pred=None)
52
+ assert log_question_result(r) == "parse_fail"