Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions tests/v1/test_scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,39 @@ def test_parse_pytest_outcomes_strips_xfail_xpass_reasons() -> None:
}


def test_parse_judge_choice_uses_first_choice_after_verdict_marker() -> None:
response = "Final Judgment: B because it is a better answer"

assert vf.parse_judge_choice(response, choices=("A", "B")) == "B"
def test_parse_judge_choice_prefers_final_marker_then_boxed() -> None:
assert (
vf.parse_judge_choice(
"Draft: \\boxed{A}\nFinal Judgment: B", choices=("A", "B")
)
== "B"
)
assert (
vf.parse_judge_choice(
"Draft: \\boxed{A}\nFinal Judgment:\nReasoning mentions B",
choices=("A", "B"),
)
== "A"
)
assert (
vf.parse_judge_choice(
"Draft: \\boxed{B}\nFinal Judgment: This is a \\boxed{B}",
choices=("A", "B"),
)
== "B"
)
assert (
vf.parse_judge_choice(
"Final Judgment: A better choice is \\boxed{B}", choices=("A", "B")
)
== "A"
)
assert (
vf.parse_judge_choice(
"Final Judgment: \\boxed{A}\nFinal Judgment: B", choices=("A", "B")
)
== "B"
)
assert (
vf.parse_judge_choice("Draft: \\boxed{A}\nAnswer: B", choices=("A", "B")) == "A"
)
15 changes: 13 additions & 2 deletions verifiers/v1/utils/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,23 @@ def parse_judge_choice(
return None

text = content.rsplit("</think>", 1)[-1].strip()
text = extract_boxed_answer(text, strict=True).strip() or text

text_upper = text.upper()
choices_by_upper = {choice.upper(): choice for choice in choices}
allowed = "|".join(re.escape(choice) for choice in choices_by_upper)
choice_re = rf"(?<!\w)({allowed})(?!\w)"
horizontal_space = r"[^\S\n]"
final_choices = re.findall(
rf"^{horizontal_space}*FINAL{horizontal_space}+"
rf"(?:JUDGMENT|ANSWER|VERDICT){horizontal_space}*"
rf"(?:IS{horizontal_space}*)?[:\-]?{horizontal_space}*{choice_re}",
text_upper,
re.MULTILINE,
)
if final_choices:
return choices_by_upper.get(final_choices[-1])

text = extract_boxed_answer(text, strict=True).strip() or text
text_upper = text.upper()
verdict_re = (
r"(?:^|\n)\s*(?:FINAL\s+JUDGMENT|FINAL\s+ANSWER|FINAL\s+VERDICT|"
r"JUDGMENT|VERDICT|ANSWER)\s*(?:IS\s*)?[:\-]?\s*"
Expand Down