basic-math-rl / README.md
CrowdMind's picture
Add elementary math dataset for NanoChat RL
3333add verified
|
Raw History Blame Contribute Delete
3.55 kB
metadata
language:
  - en
task_categories:
  - question-answering
tags:
  - math
  - synthetic
  - reinforcement-learning
  - nanochat
size_categories:
  - 10K<n<100K
configs:
  - config_name: default
    data_files:
      - split: train
        path: train.jsonl
      - split: validation
        path: validation.jsonl

Elementary Math for NanoChat RL

This dataset contains synthetic elementary school math problems in English, with short reference answers for reinforcement learning with verifiable rewards.

File Problems Problems per topic
train.jsonl 12,000 1,000
validation.jsonl 1,200 100

The 12 topics are addition, subtraction, multiplication, exact division, division with remainders, place value, rounding, fractions of a group, fraction addition and subtraction, time, US money, and rectangle area and perimeter. The prompts include direct calculations and short word problems. Both splits use the same question templates with disjoint underlying facts, including reordered operands and corresponding inverse arithmetic problems.

Format and rewards

Each line is a JSON object with a topic, an answer type, and two NanoChat messages.

{"topic":"division","answer_kind":"number","messages":[{"role":"user","content":"What is 462 ÷ 6?\n\nEnd with a line that starts with #### followed by your answer."},{"role":"assistant","content":"#### 77"}]}

NanoChat's completion renderer removes the reference assistant turn before rollout. The task loader uses that turn to compute a reward of 1 for a correct final answer and 0 otherwise. It accepts a single answer on the final line, including the requested marker, and normalizes common equivalent forms such as 1,200 and 1200, 2/4 and 1/2, or 7:05 pm and 07:05 P.M.. A remainder answer must give both the quotient and the remainder. Geometry and elapsed-time answers may include the unit requested in the prompt.

Use with NanoChat

Copy elementary_math.py into the NanoChat checkout's tasks/ directory. Add this option alongside the other arguments in scripts/chat_rl.py, before parse_args().

parser.add_argument("--elementary-math-dir", help="Directory containing the elementary math JSONL splits")

At the point where chat_rl.py creates train_task and val_task, give the new option priority.

if args.elementary_math_dir:
    from tasks.elementary_math import ElementaryMath

    train_task = ElementaryMath("train", args.elementary_math_dir)
    val_task = ElementaryMath("validation", args.elementary_math_dir)

Follow that block with the checkout's existing task selection. In a checkout that has a compact-thinking branch, change its if args.task == "compact-thinking": to elif args.task == "compact-thinking":. In a checkout with only GSM8K, put the existing GSM8K assignments under else:.

From the NanoChat checkout, download both JSONL files and point the RL runner to their directory. Use your usual RL environment and SFT checkpoint.

hf download CrowdMind/basic-math-rl train.jsonl validation.jsonl --repo-type dataset --local-dir ./basic-math-rl
python -m scripts.chat_rl --elementary-math-dir ./basic-math-rl

Regenerate the dataset

The generator uses Python 3.10+ and the standard library. This command reproduces the provided files with seed 42. Choose a different output directory to keep a second generated copy.

python generate.py --seed 42 --train-per-topic 1000 --validation-per-topic 100