Download code/replication.py from PugarHuda/benak: direct link, hf CLI and curl.
- Browser
- Download file 1.71 kB
-
https://huggingface.co/datasets/PugarHuda/benak/resolve/main/code/replication.py
- Command line
-
hf download hf://datasets/PugarHuda/benak/code/replication.py
-
curl -L -o replication.py https://huggingface.co/datasets/PugarHuda/benak/resolve/main/code/replication.py
1.71 kB
| """Zero-cost extension of the atlas: measure reasoning language on Beam traces other entrants already published | |
| (neulketing Korean, esscor TamilBench). Output: data/replication/profiled.jsonl + per-condition summary.""" | |
| import json, glob, os, statistics as st | |
| from collections import defaultdict | |
| from lid import profile | |
| ROOT = os.path.dirname(os.path.abspath(__file__)) | |
| rows = [] | |
| for f in glob.glob(os.path.join(ROOT, "data/replication/traces/*.jsonl")): | |
| for l in open(f, encoding="utf-8"): | |
| r = json.loads(l) | |
| r["lid"] = profile(r["reasoning"], r["language"]) | |
| rows.append(r) | |
| with open(os.path.join(ROOT, "data/replication/profiled.jsonl"), "w", encoding="utf-8") as f: | |
| f.writelines(json.dumps(r, ensure_ascii=False) + "\n" for r in rows) | |
| g = defaultdict(list) | |
| for r in rows: | |
| cond = r["condition"].split(";")[0] if r["source"].startswith("neul") else r["condition"].split(";")[1] | |
| g[(r["source"].split("/")[0], r["language"], cond, r["reasoning_effort"])].append(r) | |
| summary = [] | |
| for k, rs in sorted(g.items()): | |
| t = [r["lid"]["target_share"] for r in rs if r["lid"]["target_share"] is not None] | |
| e = [r["lid"]["eng_share"] for r in rs if r["lid"]["eng_share"] is not None] | |
| summary.append({"source": k[0], "lang": k[1], "cond": k[2], "effort": k[3], "n": len(rs), | |
| "mean_target_share": round(st.mean(t), 3) if t else None, | |
| "mean_eng_share": round(st.mean(e), 3) if e else None, | |
| "pct_mostly_target": round(100 * sum(x >= 0.5 for x in t) / len(t), 1) if t else None}) | |
| json.dump(summary, open(os.path.join(ROOT, "data/replication/profiled_summary.json"), "w"), indent=1) | |
| for s in summary: | |
| print(s) | |