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
7 changes: 4 additions & 3 deletions rllm/rewards/math_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __call__(self, task_info: dict, action: str) -> RewardOutput:
model_solution = model_response

model_answer = extract_answer(model_solution)
if model_answer is None:
if not model_answer: # None or empty string (e.g., empty \boxed{})
return RewardOutput(reward=self.config.format_error_reward, is_correct=False)

# Process the ground truth(s)
Expand All @@ -75,10 +75,11 @@ def __call__(self, task_info: dict, action: str) -> RewardOutput:
truth = str(truth)
if "\\boxed" in truth:
processed_truth = extract_answer(truth)
if processed_truth is not None:
if processed_truth: # not None and not empty
processed_ground_truths.append(processed_truth)
else:
processed_ground_truths.append(truth)
if truth.strip(): # skip empty ground truths
processed_ground_truths.append(truth)

if not processed_ground_truths:
return RewardOutput(reward=self.config.unk_error_reward, is_correct=False)
Expand Down
19 changes: 19 additions & 0 deletions tests/rewards/test_math_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,25 @@ def test_empty_ground_truth_list(self):
assert not output.is_correct
assert output.reward == 0.0

def test_empty_boxed_answer_not_rewarded(self):
"""Test that an empty \\boxed{} model answer does not receive a reward,
even when the ground truth is also empty. See GitHub issue #929."""
reward = RewardMathFn(RewardConfig())

# Case 1: empty \boxed{} with empty ground truth — should NOT get full reward
task_info = {"problem": "Some problem", "problem_type": RewardType.MATH, "data_source": "test", "ground_truth": ""}
model_response = "<think>I don't know</think>\nThe answer is \\boxed{}."
output = reward(task_info, model_response)
assert not output.is_correct
assert output.reward == 0.0 # format_error_reward, not correct_reward

# Case 2: empty \boxed{} with a valid ground truth — should NOT get full reward
task_info = {"problem": "What is 2 + 2?", "problem_type": RewardType.MATH, "data_source": "test", "ground_truth": "4"}
model_response = "<think>I give up</think>\nThe answer is \\boxed{}."
output = reward(task_info, model_response)
assert not output.is_correct
assert output.reward == 0.0

def test_custom_config_values(self):
"""Test math reward with custom configuration values."""
config = RewardConfig()
Expand Down