Upload scripts/build_v15_mix.py with huggingface_hub
Browse files- scripts/build_v15_mix.py +87 -0
scripts/build_v15_mix.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import json
|
| 3 |
+
import random
|
| 4 |
+
|
| 5 |
+
random.seed(15)
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def fingerprint(row):
|
| 9 |
+
state = row["state"] if isinstance(row["state"], str) else json.dumps(
|
| 10 |
+
row["state"], sort_keys=True)
|
| 11 |
+
questions = json.dumps(row["questions"], sort_keys=True)
|
| 12 |
+
return hashlib.md5((state + questions).encode()).hexdigest()
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def load(path):
|
| 16 |
+
try:
|
| 17 |
+
with open(path, encoding="utf-8") as f:
|
| 18 |
+
return [json.loads(line) for line in f]
|
| 19 |
+
except FileNotFoundError:
|
| 20 |
+
print("missing", path)
|
| 21 |
+
return []
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
spec = [("data/adjud_train.jsonl", 16000, 1),
|
| 25 |
+
("data/jb7_train.jsonl", 6000, 1),
|
| 26 |
+
("data/jb6_train.jsonl", 5000, 1),
|
| 27 |
+
("data/sft_v6.jsonl", 3000, 1),
|
| 28 |
+
("data/sft_v8b.jsonl", 2000, 1),
|
| 29 |
+
("data/hf4.jsonl", 4000, 1),
|
| 30 |
+
("data/hf3b.jsonl", 3000, 1),
|
| 31 |
+
("data/hf2b.jsonl", 3000, 1),
|
| 32 |
+
("data/hf5_bb.jsonl", 1500, 1),
|
| 33 |
+
("data/rl_sft_v9.jsonl", 1500, 1),
|
| 34 |
+
("data/sft_v9.jsonl", 1500, 1)]
|
| 35 |
+
|
| 36 |
+
seen = set()
|
| 37 |
+
train = []
|
| 38 |
+
for path, cap, copies in spec:
|
| 39 |
+
rows = load(path)
|
| 40 |
+
random.shuffle(rows)
|
| 41 |
+
kept = 0
|
| 42 |
+
for row in rows:
|
| 43 |
+
h = fingerprint(row)
|
| 44 |
+
if h in seen:
|
| 45 |
+
continue
|
| 46 |
+
seen.add(h)
|
| 47 |
+
row["id"] = f"v15:{path.split('/')[-1]}:{kept}:{h[:8]}"
|
| 48 |
+
train.append(row)
|
| 49 |
+
kept += 1
|
| 50 |
+
if kept >= cap:
|
| 51 |
+
break
|
| 52 |
+
print(path, kept)
|
| 53 |
+
|
| 54 |
+
rendered = load("data/adjud_rendered.jsonl")
|
| 55 |
+
unique_rendered = {}
|
| 56 |
+
for row in rendered:
|
| 57 |
+
unique_rendered.setdefault(fingerprint(row), row)
|
| 58 |
+
rendered = list(unique_rendered.values())
|
| 59 |
+
random.shuffle(rendered)
|
| 60 |
+
repeat = 8
|
| 61 |
+
for rep in range(repeat):
|
| 62 |
+
for i, row in enumerate(rendered):
|
| 63 |
+
clone = dict(row)
|
| 64 |
+
clone["id"] = f"v15:render:{rep}:{i}:{fingerprint(row)[:8]}"
|
| 65 |
+
if clone.get("group_id"):
|
| 66 |
+
clone["group_id"] = f"{clone['group_id']}-v15r{rep}"
|
| 67 |
+
train.append(clone)
|
| 68 |
+
print("rendered unique", len(rendered), "repeated", len(rendered) * repeat)
|
| 69 |
+
random.shuffle(train)
|
| 70 |
+
with open("data/v15_mix.jsonl", "w", encoding="utf-8") as f:
|
| 71 |
+
for row in train:
|
| 72 |
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 73 |
+
|
| 74 |
+
train_fps = {fingerprint(row) for row in train}
|
| 75 |
+
dev, dev_seen = [], set()
|
| 76 |
+
for path in ("data/adjud_dev.jsonl", "data/jb6_dev.jsonl", "data/jb7_dev.jsonl"):
|
| 77 |
+
for row in load(path):
|
| 78 |
+
h = fingerprint(row)
|
| 79 |
+
if h in train_fps or h in dev_seen:
|
| 80 |
+
continue
|
| 81 |
+
dev_seen.add(h)
|
| 82 |
+
row["id"] = f"v15dev:{path.split('/')[-1]}:{len(dev)}:{h[:8]}"
|
| 83 |
+
dev.append(row)
|
| 84 |
+
with open("data/v15_dev.jsonl", "w", encoding="utf-8") as f:
|
| 85 |
+
for row in dev:
|
| 86 |
+
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 87 |
+
print("train", len(train), "dev", len(dev), "train/dev overlap", len(train_fps & dev_seen))
|