| """ |
| This script is used to convert https://github.com/Open-Reasoner-Zero/Open-Reasoner-Zero |
| Usage: |
| |
| python scripts/data/rlvr/open_reasoner.py --push_to_hub |
| python scripts/data/rlvr/open_reasoner.py --push_to_hub --hf_entity ai2-adapt-dev |
| """ |
|
|
| from collections import defaultdict |
| from dataclasses import dataclass |
| import os |
| from typing import Optional |
|
|
| import datasets |
| from huggingface_hub import HfApi |
| from huggingface_hub.repocard import RepoCard |
| from transformers import HfArgumentParser |
|
|
| @dataclass |
| class Args: |
| push_to_hub: bool = False |
| hf_entity: Optional[str] = None |
|
|
| def main(args: Args): |
| |
| import requests |
| import json |
|
|
| file_path = "/weka/oe-adapt-default/nouhad/data/multiplication/multiplication_3_by_4_100_train.jsonl" |
| |
| |
| |
| |
| |
| |
| with open(file_path, "r") as f: |
| data = f.readlines() |
|
|
| new_data = [] |
| for item in data: |
| item = item.strip() |
| if not item: |
| continue |
| new_data.append(json.loads(item)) |
|
|
| |
|
|
| table = defaultdict(list) |
| for item in new_data: |
| assert len(item) == 3 |
| assert "problem" in item and "answer" in item, "Missing expected keys in data" |
| table["messages"].append([ |
| {"role": "user", "content": item["problem"]}, |
| {"role": "assistant", "content": item["answer"]}, |
| ]) |
| table["ground_truth"].append(item["answer"]) |
| table["dataset"].append("multiplication") |
| dataset = datasets.Dataset.from_dict(table) |
|
|
| if args.push_to_hub: |
| api = HfApi() |
| if not args.hf_entity: |
| args.hf_entity = HfApi().whoami()["name"] |
| repo_id = f"{args.hf_entity}/multiplication_3_by_4_1000_train" |
| 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 args.push_to_hub: |
| api = HfApi() |
| if not args.hf_entity: |
| args.hf_entity = HfApi().whoami()["name"] |
| repo_id = f"{args.hf_entity}/rlvr_open_reasoner_math" |
| 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, |
| ) |
|
|
| |
| repo_card = RepoCard( |
| content=f"""\ |
| # Open Reasoner Dataset |
| |
| This dataset is converted from [Open-Reasoner-Zero](https://github.com/Open-Reasoner-Zero/Open-Reasoner-Zero)'s math dataset. |
| |
| Check out https://github.com/allenai/open-instruct/blob/main/scripts/data/rlvr/open_reasoner.py for the conversion script. |
| |
| ## Dataset Format |
| |
| The dataset contains math problems and their solutions in a conversational format: |
| |
| - `messages`: List of message dictionaries with user questions and assistant answers |
| - `ground_truth`: The correct solution for each problem |
| - `dataset`: Always "math" to indicate this is from the math datases""") |
| repo_card.push_to_hub( |
| repo_id, |
| repo_type="dataset", |
| ) |
|
|
| if __name__ == "__main__": |
| parser = HfArgumentParser((Args)) |
| main(*parser.parse_args_into_dataclasses()) |
|
|