Datasets:
Download lab/build_dataset.py from HuggingFaceM4/reachy-gestures-data: direct link, hf CLI and curl.
- Browser
- Download file 2.87 kB
-
https://huggingface.co/datasets/HuggingFaceM4/reachy-gestures-data/resolve/main/lab/build_dataset.py
- Command line
-
hf download hf://datasets/HuggingFaceM4/reachy-gestures-data/lab/build_dataset.py
-
curl -L -o build_dataset.py https://huggingface.co/datasets/HuggingFaceM4/reachy-gestures-data/resolve/main/lab/build_dataset.py
2.87 kB
| """Assemble train/val (gpt-oss labels) and the agreed test sets into data/: python build_dataset.py""" | |
| import json | |
| import hashlib | |
| from pathlib import Path | |
| from labels import MOVES | |
| from hard_cases import CASES | |
| out = Path("data") | |
| out.mkdir(exist_ok=True) | |
| labels = {k: MOVES[k] + ["none"] for k in MOVES} | |
| (out / "labels.json").write_text(json.dumps(labels, indent=1)) | |
| def meta(path: str) -> dict[tuple[str, str], dict]: | |
| info = {} | |
| for line in open(path): | |
| r = json.loads(line) | |
| for s in r["sentences"]: | |
| info.setdefault((r["kind"], s.strip()), {k: r.get(k) for k in ("req", "language", "target", "source", "model")}) | |
| return info | |
| def labelled(path: str) -> dict[tuple[str, str], dict]: | |
| return {(r["kind"], r["text"]): r for r in map(json.loads, open(path))} if Path(path).exists() else {} | |
| def held_out(req: str, percent: int) -> bool: | |
| return int(hashlib.md5(req.encode()).hexdigest(), 16) % 100 < percent | |
| def write(name: str, rows: list[dict]) -> None: | |
| with open(out / f"{name}.jsonl", "w") as f: | |
| f.writelines(json.dumps(r, ensure_ascii=False) + "\n" for r in rows) | |
| none = sum(r["best"] == "none" for r in rows) | |
| print(f"{name}: {len(rows)} rows, {none / max(1, len(rows)):.0%} none") | |
| train, val = [], [] | |
| for gen, lab in (("gen_train.jsonl", "lab_train_gptoss.jsonl"), ("gen_train2.jsonl", "lab_train2_gptoss.jsonl"), ("real.jsonl", "lab_real_gptoss.jsonl")): | |
| info, labs = meta(gen), labelled(lab) | |
| real_test = {json.loads(line)["req"] for line in open("real_test.jsonl")} | |
| for key, lab_row in labs.items(): | |
| m = info[key] | |
| row = {"kind": key[0], "text": key[1], "best": lab_row["best"], "ok": lab_row["ok"], **m} | |
| if m["req"] in real_test: | |
| continue | |
| (val if gen.startswith("gen_train") and held_out(m["req"], 8) else train).append(row) | |
| write("train", train) | |
| write("val", val) | |
| def agreed(gen: str, lab_a: str, lab_b: str) -> list[dict]: | |
| info, a, b = meta(gen), labelled(lab_a), labelled(lab_b) | |
| rows, dropped = [], 0 | |
| for key in a.keys() & b.keys(): | |
| x, y = a[key], b[key] | |
| if x["best"] in y["ok"] and y["best"] in x["ok"]: | |
| ok = sorted(set(x["ok"]) & set(y["ok"])) | |
| rows.append({"kind": key[0], "text": key[1], "best": x["best"], "ok": ok, **info[key]}) | |
| else: | |
| dropped += 1 | |
| print(f"{gen}: teachers agree on {len(rows)} of {len(rows) + dropped}") | |
| return rows | |
| write("test_real", agreed("real_test.jsonl", "lab_real_gptoss.jsonl", "lab_realtest_glm.jsonl")) | |
| if Path("lab_test_glm.jsonl").exists(): | |
| write("test", agreed("gen_test.jsonl", "lab_test_gptoss.jsonl", "lab_test_glm.jsonl")) | |
| hard = [{"kind": kind, "text": text, "best": sorted(exp or {"none"})[0], "ok": sorted(exp or {"none"}), "cat": cat} | |
| for cat, kind, text, exp in CASES] | |
| write("hard", hard) | |