Spaces:
Running
Running
Download scripts/make_split.py from ruhzi/foresightbench-rl: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/ruhzi/foresightbench-rl/resolve/main/scripts/make_split.py
- Command line
-
hf download hf://spaces/ruhzi/foresightbench-rl/scripts/make_split.py
-
curl -L -o make_split.py https://huggingface.co/spaces/ruhzi/foresightbench-rl/resolve/main/scripts/make_split.py
1.85 kB
| """Build the RL splits from the ForesightBench release files. | |
| python scripts/make_split.py --corpus ../benchmark-release/full_corpus.jsonl \ | |
| --eval ../benchmark-release/eval_set.jsonl --out foresightbench_env/data/ | |
| train = every corpus row (457 rows over 71 papers); eval = the published 71-row | |
| ForesightBench eval set (one row per paper). The two share papers: every eval | |
| paper also has rows in train. This is deliberate (all samples are training | |
| samples); report eval numbers with that caveat. | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| KEEP = ("sample_id", "arxiv_id", "title", "source_license", "prompt", "asked", "target", "meta", "in_eval_set") | |
| def read_jsonl(path: Path) -> list[dict]: | |
| with path.open(encoding="utf-8") as fh: | |
| return [json.loads(l) for l in fh if l.strip()] | |
| def write_jsonl(path: Path, rows: list[dict]) -> None: | |
| with path.open("w", encoding="utf-8") as fh: | |
| for r in rows: | |
| fh.write(json.dumps({k: r[k] for k in KEEP if k in r}, ensure_ascii=False) + "\n") | |
| def main() -> None: | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--corpus", type=Path, required=True) | |
| ap.add_argument("--eval", type=Path, required=True) | |
| ap.add_argument("--out", type=Path, default=Path("foresightbench_env/data")) | |
| a = ap.parse_args() | |
| corpus = read_jsonl(a.corpus) | |
| eval_rows = read_jsonl(a.eval) | |
| a.out.mkdir(parents=True, exist_ok=True) | |
| ids = sorted(r["arxiv_id"] for r in eval_rows) | |
| (a.out / "eval_papers.txt").write_text("\n".join(ids) + "\n") | |
| write_jsonl(a.out / "eval.jsonl", eval_rows) | |
| write_jsonl(a.out / "train.jsonl", corpus) | |
| print(f"eval rows: {len(eval_rows)} train rows: {len(corpus)}") | |
| if __name__ == "__main__": | |
| main() | |