eyad-silx commited on
Commit
3d5a84d
·
verified ·
1 Parent(s): f559eae

push artifacts/scripts/make_traindata.py

Browse files
Files changed (1) hide show
  1. artifacts/scripts/make_traindata.py +59 -0
artifacts/scripts/make_traindata.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Quick training-data builder: a few corpus shards at the eval-156 commit, rows with short
2
+ prompts, dumped as drawn.jsonl (the dataset.load format). No ranking needed: the QAT trains on
3
+ any diverse rows; the margin is verified on the official harness later."""
4
+ import json
5
+ import sys
6
+ import urllib.request
7
+ from pathlib import Path
8
+
9
+ sys.path.insert(0, "/root/ingot/src")
10
+ import pyarrow.parquet as pq
11
+
12
+ COMMIT = "70d2121e5dcbfc9f2c2e79c890563d96429eeb98"
13
+ REPO = "dendriteholdings/ingot_corpus"
14
+ BASE = f"https://huggingface.co/datasets/{REPO}/resolve/{COMMIT}/"
15
+
16
+ req = urllib.request.Request(
17
+ f"https://huggingface.co/api/datasets/{REPO}/tree/{COMMIT}?recursive=1",
18
+ headers={"User-Agent": "mk"},
19
+ )
20
+ tree = json.load(urllib.request.urlopen(req))
21
+ shards = sorted(
22
+ t["path"] for t in tree if t["path"].startswith("data/chungus-") and t["path"].endswith(".parquet")
23
+ )
24
+ print("shards:", len(shards))
25
+
26
+ out = []
27
+ tmp = Path("/tmp/shards")
28
+ tmp.mkdir(exist_ok=True)
29
+ for shard in shards[::17]: # ~15 shards, spread over the corpus
30
+ url = BASE + shard
31
+ local = tmp / Path(shard).name
32
+ urllib.request.urlretrieve(url, local)
33
+ parq = pq.ParquetFile(local)
34
+ cols = ["dataset", "split", "entry_name", "domain", "language", "user_prompt"]
35
+ if "conversation" in parq.schema_arrow.names:
36
+ cols.append("conversation")
37
+ df = parq.read(columns=cols).to_pylist()
38
+ for row in df:
39
+ if row.get("conversation"):
40
+ conv = json.loads(row["conversation"])
41
+ msgs, tools = conv["messages"], conv.get("tools")
42
+ else:
43
+ msgs = [{"role": "user", "content": row["user_prompt"]}]
44
+ tools = None
45
+ size = sum(len(m["content"].encode()) for m in msgs)
46
+ if size > 3500: # short-ish prompts only
47
+ continue
48
+ sid = f"{row['dataset']}/{row['split']}/{row['entry_name']}/{row['language']}"
49
+ out.append({"id": sid, "messages": msgs, "tools": tools})
50
+ if len(out) >= 160:
51
+ break
52
+ print(f"{shard}: {len(out)} kept", flush=True)
53
+ if len(out) >= 160:
54
+ break
55
+
56
+ Path("/root/drawn.jsonl").write_text(
57
+ "".join(json.dumps(r, ensure_ascii=False) + "\n" for r in out)
58
+ )
59
+ print("wrote /root/drawn.jsonl:", len(out), "rows")