Download convert_rlcd.py from Akahsizrr/alea-runs: direct link, hf CLI and curl.
- Browser
- Download file 2.74 kB
-
https://huggingface.co/datasets/Akahsizrr/alea-runs/resolve/a8b1d98afdebd5701efb618af27bc552004a7855/convert_rlcd.py
- Command line
-
hf download hf://datasets/Akahsizrr/alea-runs@a8b1d98afdebd5701efb618af27bc552004a7855/convert_rlcd.py
-
curl -L -o convert_rlcd.py https://huggingface.co/datasets/Akahsizrr/alea-runs/resolve/a8b1d98afdebd5701efb618af27bc552004a7855/convert_rlcd.py
2.74 kB
| import hashlib, json, random | |
| from huggingface_hub import hf_hub_download | |
| random.seed(42) | |
| def conv(path, cap): | |
| rows = [] | |
| for line in open(path): | |
| r = json.loads(line) | |
| qs, tgts = [], [] | |
| for qid, q in r["questions"].items(): | |
| t = q["type"] | |
| if t == "noul": | |
| p = float(q["reference"]) | |
| if not 0.0 <= p <= 1.0: | |
| continue | |
| qs.append({"kind": "noul", "options": ["false", "true"], | |
| "text": q["instructions"], "unknown_allowed": False}) | |
| tgts.append([1.0 - p, p]) | |
| elif t == "choice": | |
| crit = q["criteria"] | |
| keys = list(crit.keys()) | |
| ref = q["reference"] | |
| if any(k not in ref for k in keys) or len(keys) < 2: | |
| continue | |
| qs.append({"kind": "choice", "options": [f"{k}: {crit[k]}" for k in keys], | |
| "text": q["instructions"], "unknown_allowed": False}) | |
| tgts.append([float(ref[k]) for k in keys]) | |
| elif t == "score": | |
| crit, ref = q["criteria"], q["reference"] | |
| if len(crit) != len(ref): | |
| continue | |
| qs.append({"kind": "score", "options": [f"{i} - {c}" for i, c in enumerate(crit)], | |
| "text": q["instructions"], "unknown_allowed": False}) | |
| tgts.append([float(x) for x in ref]) | |
| if not qs: | |
| continue | |
| st = r["state"] if isinstance(r["state"], str) else json.dumps(r["state"], sort_keys=True) | |
| gid = hashlib.sha256(st.encode()).hexdigest()[:16] | |
| rows.append({"state": st, "id": f"rlcd:{r.get('domain','?')}:{gid}:{len(rows)}", | |
| "questions": qs, "targets": tgts, | |
| "source": f"rlcd:{r.get('domain','?')}", "group_id": f"rlcd:{gid}"}) | |
| if len(rows) >= cap: | |
| break | |
| return rows | |
| tr = conv(hf_hub_download("soyrsoyr/openjev-rlcd-v0", "train.jsonl", repo_type="dataset"), 26000) | |
| dv = conv(hf_hub_download("soyrsoyr/openjev-rlcd-v0", "val.jsonl", repo_type="dataset"), 4000) | |
| trg = {r["group_id"] for r in tr} | |
| dv = [r for r in dv if r["group_id"] not in trg] | |
| random.shuffle(tr) | |
| with open("/root/alea/data/rlcd_train.jsonl", "w") as f: | |
| for r in tr: | |
| f.write(json.dumps(r) + "\n") | |
| with open("/root/alea/data/rlcd_dev.jsonl", "w") as f: | |
| for r in dv: | |
| f.write(json.dumps(r) + "\n") | |
| print({"train": len(tr), "dev": len(dv), | |
| "train_qs": sum(len(r["questions"]) for r in tr), | |
| "kinds": {k: sum(1 for r in tr for q in r["questions"] if q["kind"] == k) | |
| for k in ("choice", "noul", "score")}}) | |