Download code/refined_math/curriculum.py from davidheineman/tiny-rl-refined-math-v1: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/datasets/davidheineman/tiny-rl-refined-math-v1/resolve/main/code/refined_math/curriculum.py
- Command line
-
hf download hf://datasets/davidheineman/tiny-rl-refined-math-v1/code/refined_math/curriculum.py
-
curl -L -o curriculum.py https://huggingface.co/datasets/davidheineman/tiny-rl-refined-math-v1/resolve/main/code/refined_math/curriculum.py
1.1 kB
| import random | |
| from .data import small_final_calculation | |
| from .envs import Pool, make_episode | |
| class SmallCalculationPool(Pool): | |
| fraction: float = .8 | |
| def __init__(self, rows: list[dict]): | |
| if not 0 <= self.fraction <= 1: | |
| raise ValueError('Small-calculation sampling fraction must be in [0, 1]') | |
| super().__init__(rows) | |
| small = {row['group'] for row in rows | |
| if small_final_calculation(dict(steps=row['provenance']['equations']))} | |
| self.small_by_hint = {level: [row for row in selected if row['group'] in small] | |
| for level, selected in self.by_hint.items()} | |
| def sample(self, rng: random.Random): | |
| level = rng.randint(1, 16) | |
| if self.small_by_hint[level] and rng.random() < self.fraction: | |
| row = rng.choice(self.small_by_hint[level]) | |
| else: | |
| bands = list(self.by_band[level]) | |
| band = rng.choices(bands, [self.weights[name] for name in bands])[0] | |
| row = rng.choice(self.by_band[level][band]) | |
| return make_episode(row, level) | |