Files
Costa HuangandGitHub 5b0df17c70 RLVR from base (#539)
* RLVR from base

* push

* push

* quick change

* better prompt

* Fix memory leak

* revert changes

* add citation

* style quality

* pin wandb version

* update docs

* update docs

* update mini.sh
2025-02-01 09:14:46 -05:00

59 lines
1.7 KiB
Python

"""
This script is used to convert the GSM8K dataset to standard SFT format.
Note that we don't do any special processing to answer, and we will mainly
use it for generations.
Usage:
python scripts/data/gsm8k.py --push_to_hub
python scripts/data/gsm8k.py --push_to_hub --hf_entity ai2-adapt-dev
"""
from dataclasses import dataclass
from typing import Optional
import datasets
from huggingface_hub import HfApi
from transformers import HfArgumentParser
@dataclass
class Args:
push_to_hub: bool = False
hf_entity: Optional[str] = None
def main(args: Args):
dataset = datasets.load_dataset("gsm8k", "main")
def process(example):
# extract answer; it's after #### in the answer
example["ground_truth"] = example["answer"].split("####")[1].strip()
example["dataset"] = "gsm8k"
example["messages"] = [
{"role": "user", "content": example["question"]},
{"role": "assistant", "content": example["answer"]},
]
return example
dataset = dataset.map(process)
for key in dataset: # reorder columns
dataset[key] = dataset[key].select_columns(
["messages", "ground_truth", "dataset"]
)
if args.push_to_hub:
api = HfApi()
if not args.hf_entity:
args.hf_entity = HfApi().whoami()["name"]
repo_id = f"{args.hf_entity}/rlvr_gsm8k_zs"
print(f"Pushing dataset to Hub: {repo_id}")
dataset.push_to_hub(repo_id)
api.upload_file(
path_or_fileobj=__file__,
path_in_repo="create_dataset.py",
repo_type="dataset",
repo_id=repo_id,
)
if __name__ == "__main__":
parser = HfArgumentParser((Args))
main(*parser.parse_args_into_dataclasses())