Skip to content

Commit

Permalink
Improve word splitting / text matching (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonstyle authored Nov 26, 2024
1 parent 9228626 commit 0f9c96c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/inspect_ai/scorer/_common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import re
from typing import Callable, Literal

from inspect_ai._util.text import (
Expand Down Expand Up @@ -67,10 +68,10 @@ def match_str(
# normalize as required
t = normalize_number(t)
if location == "begin":
words = v.split(" ")
words = re.split(r"\s+", v)
v = first_number_normalized(words)
elif location == "end":
words = v.split(" ")
words = re.split(r"\s+", v)
words.reverse()
v = first_number_normalized(words)
elif location == "exact":
Expand Down
13 changes: 13 additions & 0 deletions tests/scorer/test_match.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pytest
from test_helpers.utils import simple_task_state

from inspect_ai.scorer import CORRECT, Target, match


@pytest.mark.asyncio
async def test_number_eol():
scorer = match(numeric=True)
state = simple_task_state(model_output="28 + 32 = 60\nThis solves the problem.")
result = await scorer(state, Target(["60"]))

assert result.text == CORRECT

0 comments on commit 0f9c96c

Please sign in to comment.