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
6 changes: 6 additions & 0 deletions lmms_eval/api/reasoning.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ def strip_reasoning_tags(text: str, tag_pairs: List[List[str]]) -> str:
result = result[:start] + result[end + len(end_tag) :]
else:
break
# Some chat templates prefill the opening reasoning tag in the prompt,
# so the model completion may contain only the closing tag plus the
# final answer. In that case, keep the suffix after the final closing
# tag so downstream scorers see the answer instead of the reasoning.
if end_tag in result and start_tag not in result:
result = result.rsplit(end_tag, 1)[-1]
return result.strip()


Expand Down
13 changes: 13 additions & 0 deletions test/eval/test_reasoning.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from lmms_eval.api.reasoning import strip_reasoning_tags


def test_strip_reasoning_tags_removes_paired_block():
text = "<think>\nreasoning\n</think>\n\nYes"
cleaned = strip_reasoning_tags(text, [["<think>", "</think>"]])
assert cleaned == "Yes"


def test_strip_reasoning_tags_handles_prompt_prefilled_opening_tag():
text = "reasoning from completion only\n</think>\n\nNo"
cleaned = strip_reasoning_tags(text, [["<think>", "</think>"]])
assert cleaned == "No"