Datasets:
Download lab/build_dataset2.py from HuggingFaceM4/reachy-gestures-data: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/datasets/HuggingFaceM4/reachy-gestures-data/resolve/main/lab/build_dataset2.py
- Command line
-
hf download hf://datasets/HuggingFaceM4/reachy-gestures-data/lab/build_dataset2.py
-
curl -L -o build_dataset2.py https://huggingface.co/datasets/HuggingFaceM4/reachy-gestures-data/resolve/main/lab/build_dataset2.py
3.61 kB
| """Training sets that combine gpt-oss-120b and Kimi-K3 labels: python build_dataset2.py | |
| Writes splits/{gptoss,kimi,agreed,merged}/ with train.jsonl, a shared val.jsonl (gen_train* sentences held out by request, | |
| kept only where both labellers agree), and the unchanged test, test_real, hard and labels files from data/. | |
| gptoss every sentence, gpt-oss labels (baseline with the shared val) | |
| kimi every sentence, Kimi-K3's labels | |
| agreed only sentences where the two labellers are compatible (each one's best is in the other's ok set); | |
| ok = intersection, best = Kimi's | |
| merged agreed sentences as above, plus disagreements with ok = union and best = Kimi's | |
| """ | |
| import json | |
| import shutil | |
| import hashlib | |
| from pathlib import Path | |
| def meta(path: str) -> dict[tuple[str, str], dict]: # same as build_dataset.py, which runs on import | |
| 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 | |
| out = Path("splits") | |
| SOURCES = (("gen_train.jsonl", "lab_train_gptoss.jsonl", "lab_train_kimi.jsonl"), | |
| ("gen_train2.jsonl", "lab_train2_gptoss.jsonl", "lab_train2_kimi.jsonl"), | |
| ("real.jsonl", "lab_real_gptoss.jsonl", "lab_real_kimi.jsonl")) | |
| real_test = {json.loads(line)["req"] for line in open("real_test.jsonl")} | |
| variants: dict[str, list[dict]] = {"gptoss": [], "kimi": [], "agreed": [], "merged": []} | |
| val: list[dict] = [] | |
| stats = {"both": 0, "compatible": 0} | |
| for gen, lab_o, lab_k in SOURCES: | |
| info, o, k = meta(gen), labelled(lab_o), labelled(lab_k) | |
| for key in o.keys() & k.keys(): | |
| m = info[key] | |
| if m["req"] in real_test: | |
| continue | |
| x, y = o[key], k[key] | |
| compatible = x["best"] in y["ok"] and y["best"] in x["ok"] | |
| stats["both"] += 1 | |
| stats["compatible"] += compatible | |
| base = {"kind": key[0], "text": key[1], **m} | |
| if gen.startswith("gen_train") and held_out(m["req"], 8): | |
| if compatible: | |
| val.append(base | {"best": y["best"], "ok": sorted(set(x["ok"]) & set(y["ok"]))}) | |
| continue | |
| variants["kimi"].append(base | {"best": y["best"], "ok": y["ok"]}) | |
| variants["gptoss"].append(base | {"best": x["best"], "ok": x["ok"]}) | |
| if compatible: | |
| row = base | {"best": y["best"], "ok": sorted(set(x["ok"]) & set(y["ok"]))} | |
| variants["agreed"].append(row) | |
| variants["merged"].append(row) | |
| else: | |
| variants["merged"].append(base | {"best": y["best"], "ok": sorted(set(x["ok"]) | set(y["ok"]))}) | |
| print(stats, f"compatible {stats['compatible'] / stats['both']:.1%}") | |
| for name, rows in variants.items(): | |
| folder = out / name | |
| folder.mkdir(parents=True, exist_ok=True) | |
| for f in ("test.jsonl", "test_real.jsonl", "hard.jsonl", "labels.json"): | |
| shutil.copy(Path("data") / f, folder / f) | |
| for split, data in (("train", rows), ("val", val)): | |
| with open(folder / f"{split}.jsonl", "w") as fh: | |
| fh.writelines(json.dumps(r, ensure_ascii=False) + "\n" for r in data) | |
| none = sum(r["best"] == "none" for r in rows) | |
| print(f"{name}: train {len(rows)} ({none / len(rows):.0%} none), val {len(val)}") | |