Spaces:
Running

File size: 1,846 Bytes
effcad2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""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()