mirror of
https://github.com/open-thought/reasoning-gym.git
synced 2026-04-19 12:58:07 +00:00
added power function exponent (#291)
* added power function exponent * register PowerFunctionCurriculum --------- Co-authored-by: Andreas Koepf <andreas.koepf@provisio.com>
This commit is contained in:
parent
af5a6533c8
commit
a7dd5f6680
3 changed files with 46 additions and 4 deletions
|
|
@ -6,6 +6,7 @@ from math import pow
|
|||
from random import Random
|
||||
from typing import Any, Optional
|
||||
|
||||
from ..coaching import AttributeType, BaseCurriculum, RangeAttributeDefinition
|
||||
from ..factory import ProceduralDataset, register_dataset
|
||||
|
||||
QUESTION_TEMPLATE = """Your task is to compute an exponentiation of a number.
|
||||
|
|
@ -21,7 +22,7 @@ class PowerFunctionConfig:
|
|||
|
||||
min_base: float = -1e3 # Minimum base value
|
||||
max_base: float = 1e3 # Maximum base value
|
||||
min_exponent: int = -8 # Minimum exponent value
|
||||
min_exponent: int = 0 # Minimum exponent value
|
||||
max_exponent: int = 8 # Maximum exponent value
|
||||
|
||||
size: int = 500 # Virtual dataset size
|
||||
|
|
@ -63,13 +64,33 @@ class PowerFunctionDataset(ProceduralDataset):
|
|||
|
||||
base = round(rng.uniform(self.config.min_base, self.config.max_base), 4)
|
||||
exponent = rng.randint(self.config.min_exponent, self.config.max_exponent)
|
||||
|
||||
if rng.random() < 0.5:
|
||||
exponent = -exponent
|
||||
|
||||
answer = pow(base, exponent)
|
||||
|
||||
return {
|
||||
"question": QUESTION_TEMPLATE.format(base=base, exponent=exponent),
|
||||
"answer": str(answer),
|
||||
"metadata": {"base": base, "exponent": exponent, "solution": answer},
|
||||
"metadata": {"base": base, "exponent": exponent, "solution": answer, "difficulty": {"exponent": exponent}},
|
||||
}
|
||||
|
||||
|
||||
register_dataset("power_function", PowerFunctionDataset, PowerFunctionConfig)
|
||||
class PowerFunctionCurriculum(BaseCurriculum):
|
||||
def __init__(self):
|
||||
super().__init__(PowerFunctionCurriculum.__name__, PowerFunctionConfig)
|
||||
self._define_attributes(
|
||||
RangeAttributeDefinition(
|
||||
name="exponent",
|
||||
levels=[2, 4, 6, 10],
|
||||
default_level=0,
|
||||
attr_type=AttributeType.APPEND,
|
||||
min_value=2,
|
||||
lower_field_name="min_exponent",
|
||||
upper_field_name="max_exponent",
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
register_dataset("power_function", PowerFunctionDataset, PowerFunctionConfig, PowerFunctionCurriculum)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue