Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ All notable changes to SkillOpt are documented here. This project adheres to
- Skip step-level edits whose target runs into a protected slow-update or
appendix region, so a `replace` or `delete` can no longer remove the start
marker and expose the protected content (thanks @Shizoqua).
- Score LiveMathematicianBench answers written as `(B)`, `[B]`, or `**B**` as
the choice they name instead of marking them wrong (thanks @Shizoqua).

### Security
- Prevent managed-identity credentials from being sent to non-Azure or
Expand Down
3 changes: 2 additions & 1 deletion skillopt/envs/livemathematicianbench/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def extract_answer(text: str) -> str:


def normalize_label(text: str) -> str:
return str(text).strip().upper().rstrip(".):")
"""Normalize a choice label, accepting ``B``, ``B.``, ``(B)``, ``[B]`` and ``**B**``."""
return str(text).strip().strip("*").strip().lstrip("([").upper().rstrip(".):]")


def parse_choice_label(prediction_text: str, choices: list[dict]) -> str:
Expand Down
33 changes: 33 additions & 0 deletions tests/test_livemath_evaluator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pytest

from skillopt.envs.livemathematicianbench.evaluator import evaluate

CHOICES = [
{"label": "A", "text": "2"},
{"label": "B", "text": "3"},
{"label": "C", "text": "5"},
]


@pytest.mark.parametrize(
"response",
[
"<answer>B</answer>",
"<answer>B.</answer>",
"<answer>B)</answer>",
"<answer>(B)</answer>",
"<answer>[B]</answer>",
"<answer>**B**</answer>",
"<answer>(B) 3</answer>",
],
)
def test_wrapped_choice_label_is_scored_correct(response):
result = evaluate(response, CHOICES[1], CHOICES)

assert result["predicted_label"] == "B"
assert result["em"] == 1.0


@pytest.mark.parametrize("response", ["<answer>(A)</answer>", "<answer>Option B</answer>", "<answer></answer>"])
def test_wrong_or_unparseable_label_is_not_scored_correct(response):
assert evaluate(response, CHOICES[1], CHOICES)["em"] == 0.0