Skip to content

Commit 263a80c

Browse files
authored
feat(reasoning): enhance strip_reasoning_tags to handle cases with only closing tags (#1237)
1 parent 8bcf00b commit 263a80c

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

lmms_eval/api/reasoning.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ def strip_reasoning_tags(text: str, tag_pairs: List[List[str]]) -> str:
2222
result = result[:start] + result[end + len(end_tag) :]
2323
else:
2424
break
25+
# Some chat templates prefill the opening reasoning tag in the prompt,
26+
# so the model completion may contain only the closing tag plus the
27+
# final answer. In that case, keep the suffix after the final closing
28+
# tag so downstream scorers see the answer instead of the reasoning.
29+
if end_tag in result and start_tag not in result:
30+
result = result.rsplit(end_tag, 1)[-1]
2531
return result.strip()
2632

2733

test/eval/test_reasoning.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from lmms_eval.api.reasoning import strip_reasoning_tags
2+
3+
4+
def test_strip_reasoning_tags_removes_paired_block():
5+
text = "<think>\nreasoning\n</think>\n\nYes"
6+
cleaned = strip_reasoning_tags(text, [["<think>", "</think>"]])
7+
assert cleaned == "Yes"
8+
9+
10+
def test_strip_reasoning_tags_handles_prompt_prefilled_opening_tag():
11+
text = "reasoning from completion only\n</think>\n\nNo"
12+
cleaned = strip_reasoning_tags(text, [["<think>", "</think>"]])
13+
assert cleaned == "No"

0 commit comments

Comments
 (0)