File size: 2,514 Bytes
611d454
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""Write the exact benchmark prompts, one JSON row per call, for use with any model harness.

Usage:
  make_prompts.py --items splits/hard.jsonl --out prompts_hard.jsonl            # pointwise
  make_prompts.py --pairs data/pairs_hard.jsonl --out prompts_hardpairs.jsonl   # pairwise, both orders

Pointwise rows: {"id", "system", "prompt", "prompt_sha256"}.
Pairwise rows:  {"pair_id", "order", "system", "prompt", "prompt_sha256"}.
Send "system" as the system message and "prompt" as the user message. Write the model's reply
to a predictions file as {"id": ..., "response": REPLY} (or "pair_id"/"order"/"response"), then
run scripts/score.py on it.
"""
import argparse
import json
import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent))
from pocb import JUDGE_SYSTEM, ROOT, group, load_jsonl, pairwise_prompt, pointwise_prompt, prompt_sha256  # noqa: E402


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--items", help="items file (pointwise)")
    ap.add_argument("--pairs", help="pairs file (pairwise); items are read from data/items.jsonl")
    ap.add_argument("--out", required=True)
    ap.add_argument("--with-labels", action="store_true",
                    help="pointwise only: add label, group and fold (for a self-scoring task such as the Kaggle one)")
    a = ap.parse_args()
    if bool(a.items) == bool(a.pairs):
        ap.error("give exactly one of --items or --pairs")
    rows = []
    if a.items:
        for it in load_jsonl(a.items):
            p = pointwise_prompt(it)
            row = {"id": it["id"], "system": JUDGE_SYSTEM, "prompt": p, "prompt_sha256": prompt_sha256(p)}
            if a.with_labels:
                row.update(label=it["label"], group=group(it), fold=it.get("fold", ""))
            rows.append(row)
    else:
        by_id = {it["id"]: it for it in load_jsonl(ROOT / "data/items.jsonl")}
        for pr in load_jsonl(a.pairs):
            P, U = by_id[pr["proven_id"]], by_id[pr["unproven_id"]]
            for order, (x, y) in (("PU", (P, U)), ("UP", (U, P))):
                p = pairwise_prompt(x, y)
                rows.append({"pair_id": pr["id"], "order": order, "system": JUDGE_SYSTEM, "prompt": p,
                             "prompt_sha256": prompt_sha256(p)})
    with open(a.out, "w") as f:
        for r in rows:
            f.write(json.dumps(r, ensure_ascii=False) + "\n")
    print(f"wrote {len(rows)} prompts to {a.out}")


if __name__ == "__main__":
    main()