Upload scripts/build_v12_mix.py with huggingface_hub
Browse files- scripts/build_v12_mix.py +58 -0
scripts/build_v12_mix.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib, json, random
|
| 2 |
+
from collections import Counter
|
| 3 |
+
random.seed(12)
|
| 4 |
+
D = "/root/alea/data/"
|
| 5 |
+
SPECS = [
|
| 6 |
+
("openjev_train.jsonl", 40000),
|
| 7 |
+
("tev1_train.jsonl", 30000),
|
| 8 |
+
("jevdec_train_v2.jsonl", 18000),
|
| 9 |
+
("tasksource_train.canon.jsonl", 40000),
|
| 10 |
+
("rlcd_train.canon.jsonl", 8000),
|
| 11 |
+
("tot_train.canon.jsonl", 4500),
|
| 12 |
+
("genhard_train.canon.jsonl", 23000),
|
| 13 |
+
("gh2_train.jsonl", 22507),
|
| 14 |
+
("reason_train.jsonl", 16544),
|
| 15 |
+
("sft_v6.jsonl", 12000),
|
| 16 |
+
("sft_v8b.jsonl", 8000),
|
| 17 |
+
("jb7_train.jsonl", 10000),
|
| 18 |
+
("jb6_train.jsonl", 6000),
|
| 19 |
+
]
|
| 20 |
+
DEV_SPECS = [
|
| 21 |
+
("openjev_validation.jsonl", 1000), ("tev1_dev.jsonl", 1000),
|
| 22 |
+
("tev1_transfer.jsonl", 800),
|
| 23 |
+
("tasksource_dev.canon.jsonl", 1200), ("rlcd_dev.canon.jsonl", 800),
|
| 24 |
+
("tot_dev.canon.jsonl", 311), ("genhard_dev.canon.jsonl", 1200),
|
| 25 |
+
("gh2_dev.jsonl", 1200), ("reason_dev.jsonl", 1096),
|
| 26 |
+
("jb7_dev.jsonl", 1500),
|
| 27 |
+
]
|
| 28 |
+
def load(fn, cap):
|
| 29 |
+
rows = [json.loads(l) for l in open(D + fn)]
|
| 30 |
+
random.shuffle(rows)
|
| 31 |
+
return rows[:cap]
|
| 32 |
+
fps, mix, stats = set(), [], Counter()
|
| 33 |
+
for fn, cap in SPECS:
|
| 34 |
+
try:
|
| 35 |
+
rows = load(fn, cap)
|
| 36 |
+
except FileNotFoundError:
|
| 37 |
+
print("MISSING", fn); continue
|
| 38 |
+
kept = 0
|
| 39 |
+
for r in rows:
|
| 40 |
+
st = json.dumps(r["state"], sort_keys=True, ensure_ascii=False)
|
| 41 |
+
qs = r.get("questions") or [{"text": r.get("question"), "options": r.get("options")}]
|
| 42 |
+
fp = hashlib.sha256((st + json.dumps(qs, sort_keys=True, ensure_ascii=False)).encode()).hexdigest()
|
| 43 |
+
if fp in fps: continue
|
| 44 |
+
fps.add(fp); mix.append(r); kept += 1
|
| 45 |
+
stats[fn] = kept
|
| 46 |
+
random.shuffle(mix)
|
| 47 |
+
with open(D + "v12_mix.jsonl", "w") as f:
|
| 48 |
+
for r in mix: f.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 49 |
+
dev, dstats = [], Counter()
|
| 50 |
+
for fn, cap in DEV_SPECS:
|
| 51 |
+
try: rows = load(fn, cap)
|
| 52 |
+
except FileNotFoundError: print("DEV MISSING", fn); continue
|
| 53 |
+
dev.extend(rows); dstats[fn] = len(rows)
|
| 54 |
+
random.shuffle(dev)
|
| 55 |
+
with open(D + "v12_dev.jsonl", "w") as f:
|
| 56 |
+
for r in dev: f.write(json.dumps(r, ensure_ascii=False) + "\n")
|
| 57 |
+
print("mix:", len(mix), dict(stats))
|
| 58 |
+
print("dev:", len(dev), dict(dstats))
|