mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-19 12:58:07 +00:00
add a helper function to handle redundant code
This commit is contained in:
parent
5c45e55340
commit
5d02064b5a
4 changed files with 35 additions and 37 deletions
|
|
@ -2,6 +2,8 @@ import random
|
|||
from dataclasses import dataclass
|
||||
from typing import Dict, Optional
|
||||
|
||||
from reasoning_gym import utils
|
||||
|
||||
from ..coaching import AttributeType, BaseCurriculum, RangeAttributeDefinition
|
||||
from ..factory import ProceduralDataset, register_dataset
|
||||
|
||||
|
|
@ -101,19 +103,8 @@ class ProductsDataset(ProceduralDataset):
|
|||
return expression, result
|
||||
|
||||
def score_answer(self, answer: Optional[str], entry: Dict[str, any]) -> float:
|
||||
"""Overwrite this method in derived classes if a single oracle answer is not available."""
|
||||
oracle_answer = entry["answer"].strip()
|
||||
reward = 0.0
|
||||
if answer is not None and len(answer) > 0:
|
||||
answer = answer.strip().replace(",", "")
|
||||
if answer == oracle_answer:
|
||||
reward = 1.0
|
||||
elif oracle_answer in answer:
|
||||
reward = len(oracle_answer) / len(answer)
|
||||
else:
|
||||
reward = 0.01
|
||||
|
||||
return reward
|
||||
return utils.compute_reward(answer, oracle_answer)
|
||||
|
||||
|
||||
class ProductsCurriculum(BaseCurriculum):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue