Upload code/build_sft_v14_dataset.py with huggingface_hub
Browse files123456789101112131415161718192021222332 unmodified lines56575859606162105 unmodified lines1681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222234 unmodified lines2282292302312322332341 unmodified line2362372382392402412422432442452462472482492502512521 unmodified line25425525625725825926026126226326426526626726826927027127227327427527627727827928028128234 unmodified lines31731831932032132232313 unmodified lines33733833934034134234318 unmodified lines3623633643653663673683693703713723733743751 unmodified line3773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174185 unmodified lines4244254264274284294304314324334344354367 unmodified lines444445446447448449450451452453102 unmodified lines5565575585595605615623 unmodified lines5665675685695705715725735745755765775785795805815825835845855865875 unmodified lines59359459559659759859960060160220 unmodified lines62362462562662762862972 unmodified lines70270370470570670770849 unmodified lines75875976076176276376448 unmodified lines813814815816817# ==============================================================================# ViuAI Sarus-500M — SFT v14 Master Dataset Builder (~380K+ High-Quality Scale)# ==============================================================================# 100% READYMADE HUGGING FACE DATASETS ONLY — ZERO SYNTHETIC MULTIPLIERS.# ZERO PERSONA FILES. ZERO EXPERIMENTAL SCRIPTS.## 9 Scaled Domains:# 0. Conversational QA (~140k) — OpenHermes-2.5, OpenOrca, Alpaca-Hindi, Alpaca-52k, Dolly-15k# 1. General Knowledge (~35k) — MMLU (57 subjects), ARC (Easy+Challenge), OpenBookQA# 2. Stories & Creative (~40k) — TinyStories (25k), Grammarly CoEdit (10k), WritingPrompts (10k)# 3. Multi-Turn (~60k) — UltraChat-200k (70k raw multi-turn sequences)# 4. Identity (~2.2k) — export_Identity_all.json (Sarus by ViuAI)# 5. Basic Math (~15k) — GSM8K (easy) + Orca Math (short word problems)# 6. Basic Coding (~25k) — CodeAlpaca-20k + Python Instructions 18k# 7. Basic Reasoning (~20k) — HellaSwag (25k clean reasoning scenarios)# 8. Translation (~50k) — IITB English-Hindi (150k raw -> ~50k deduplicated)## Vocab Size: 64,003 (Base 64,000 + <|user|> + <|assistant|> + <|endofturn|>)# Format: 100% Direct Response — no [THINK], no RAG, no persona# Target Scale: ~380,000+ Pristine Unique Samples# ==============================================================================import sys32 unmodified linesapi = HfApi(token=HF_TOKEN)print("=" * 85)print("🚀 SFT v14 Master Dataset Builder (~380K+ Pristine Readymade HF Data)")print(" ZERO Custom Local Data | ZERO Persona Files | ZERO Synthetic Multipliers")print(" Vocab: 64,003 | Format: 100% Direct Response")print("=" * 85)105 unmodified linesreturn False# ==============================================================================# --- 3. INGESTION — 9 STRATIFIED HIGH-SCALE DOMAINS ---# ==============================================================================dataset_pool = defaultdict(list)# ------------------------------------------------------------------------------# DOMAIN 0: CONVERSATIONAL QA (~140,000)# ------------------------------------------------------------------------------print("\n📥 [0/8] Ingesting Domain 0: Conversational QA (OpenHermes, OpenOrca, Alpaca Hindi, Dolly)...")# 1. OpenHermes-2.5 (~75,000)try:hermes_ds = load_dataset("teknium/OpenHermes-2.5", split="train", streaming=True)count = 0for row in hermes_ds:convs = row.get("conversations", [])if len(convs) >= 2:inst = clean_text(convs[0].get("value", ""))resp = clean_text(convs[1].get("value", ""))if inst and resp and 15 < len(resp) < 1800 and len(inst) > 8:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count += 1if count >= 75000:breakprint(f" • Loaded {count:,} OpenHermes-2.5 conversations.")except Exception as e:print(f" ⚠️ OpenHermes note: {e}")# 2. Open-Orca (~35,000 clean GPT-4 subset)try:orca_ds = load_dataset("Open-Orca/OpenOrca", split="train", streaming=True)count = 0for row in orca_ds:inst = clean_text(row.get("question", ""))resp = clean_text(row.get("response", ""))sys_p = clean_text(row.get("system_prompt", ""))full_inst = f"{sys_p}\n\n{inst}".strip() if sys_p and len(sys_p) < 300 else instif full_inst and resp and 15 < len(resp) < 1500:dataset_pool["conversational"].append({"instruction": full_inst, "response": resp})count += 1if count >= 35000:breakprint(f" • Loaded {count:,} OpenOrca instruction pairs.")except Exception as e:print(f" ⚠️ OpenOrca note: {e}")# 3. alpaca-gpt4-hindi (~15,000)try:hindi_ds = load_dataset("FreedomIntelligence/alpaca-gpt4-hindi", split="train")count = 0for row in hindi_ds:if "conversations" in row and isinstance(row["conversations"], list):inst, resp = "", ""4 unmodified linesresp = clean_text(turn.get("value", ""))if inst and resp and len(resp) < 2000:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count += 1else:inst = clean_text(row.get("instruction", row.get("prompt", "")))inp = clean_text(row.get("input", ""))1 unmodified linefull_inst = f"{inst}\n{inp}".strip() if inp else instif full_inst and out and len(out) < 2000:dataset_pool["conversational"].append({"instruction": full_inst, "response": out})count += 1if count >= 15000:breakprint(f" • Loaded {count:,} Hindi Alpaca pairs.")except Exception as e:print(f" ⚠️ Hindi Alpaca note: {e}")# 4. tatsu-lab/alpaca (~35,000)try:alpaca_ds = load_dataset("tatsu-lab/alpaca", split="train")count = 0for row in alpaca_ds:inst = clean_text(row.get("instruction", ""))inp = clean_text(row.get("input", ""))1 unmodified linefull_inst = f"{inst}\n{inp}".strip() if inp else instif full_inst and out and len(out) < 1500:dataset_pool["conversational"].append({"instruction": full_inst, "response": out})count += 1if count >= 35000:breakprint(f" • Loaded {count:,} Alpaca-52k instructions.")except Exception as e:print(f" ⚠️ Alpaca note: {e}")# 5. databricks-dolly-15k (~15,000 full)try:dolly_ds = load_dataset("databricks/databricks-dolly-15k", split="train")count = 0for row in dolly_ds:inst = clean_text(row["instruction"])ctx = clean_text(row.get("context", ""))resp = clean_text(row["response"])full_inst = f"{inst}\nContext:\n{ctx}" if ctx else instif full_inst and resp and len(resp) < 2000:dataset_pool["conversational"].append({"instruction": full_inst, "response": resp})count += 1print(f" • Loaded {count:,} Dolly-15k human tasks.")except Exception as e:print(f" ⚠️ Dolly note: {e}")print(f" ✅ Domain 0 (Conversational QA): Total {len(dataset_pool['conversational']):,} raw samples loaded.")# ------------------------------------------------------------------------------34 unmodified linesbreakprint(f" • Loaded {count_mmlu:,} MMLU academic QA pairs.")# ARC Science Questions (ARC-Easy + ARC-Challenge)count_arc = 0for arc_type in ["ARC-Easy", "ARC-Challenge"]:try:13 unmodified linespassprint(f" • Loaded {count_arc:,} ARC science questions.")# OpenBookQAtry:obqa_ds = load_dataset("openbookqa", "main", split="train")count_ob = 018 unmodified linesprint(f" ✅ Domain 1 (General Knowledge): Total {len(dataset_pool['gk']):,} raw samples loaded.")# ------------------------------------------------------------------------------# DOMAIN 2: STORIES & CREATIVE WRITING (~40,000)# ------------------------------------------------------------------------------print("\n📥 [2/8] Ingesting Domain 2: Stories & Creative Writing (TinyStories 25k + Grammarly CoEdit 10k + WritingPrompts)...")# 1. roneneldan/TinyStories (~25,000)try:ts_ds = load_dataset("roneneldan/TinyStories", split="train", streaming=True)count = 0for row in ts_ds:story_text = clean_text(row.get("text", ""))if story_text and 100 < len(story_text) < 1500:1 unmodified linefirst_line = lines[0].strip()prompt = f"Write a short, engaging story with a meaningful theme:\n\"{first_line[:120]}\""dataset_pool["stories"].append({"instruction": prompt, "response": story_text})count += 1if count >= 25000:breakprint(f" • Loaded {count:,} TinyStories creative narratives.")except Exception as e:print(f" ⚠️ TinyStories note: {e}")# 2. grammarly/coedit (~10,000)try:coedit_ds = load_dataset("grammarly/coedit", split="train")count = 0for row in coedit_ds:src = clean_text(row["src"])tgt = clean_text(row["tgt"])if src and tgt and len(src) < 1000:dataset_pool["stories"].append({"instruction": src, "response": tgt})count += 1if count >= 10000:breakprint(f" • Loaded {count:,} Grammarly text rewrites.")except Exception as e:print(f" ⚠️ CoEdit note: {e}")# 3. euclaise/writingprompts (~10,000)try:wp_ds = load_dataset("euclaise/writingprompts", split="train", streaming=True)count = 0for row in wp_ds:p = clean_text(row.get("prompt", ""))s = clean_text(row.get("story", ""))if p and s and 80 < len(s) < 1500 and len(p) > 10:dataset_pool["stories"].append({"instruction": f"Write a short story based on this prompt:\n{p}", "response": s})count += 1if count >= 10000:breakprint(f" • Loaded {count:,} WritingPrompts creative stories.")except Exception as e:print(f" ⚠️ WritingPrompts note: {e}")5 unmodified linesprint("\n📥 [3/8] Ingesting Domain 3: Multi-Turn Conversations (UltraChat 200k)...")try:ultra_ds = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft", streaming=True)count = 0for row in ultra_ds:messages = row.get("messages", [])if isinstance(messages, list) and 4 <= len(messages) <= 8:turns = []valid = Truefor i, msg in enumerate(messages[:6]): # Max 3 user-assistant pairscontent = clean_text(msg.get("content", ""))role = msg.get("role", "")if not content or len(content) > 1200:7 unmodified linesif valid and len(turns) >= 4:all_text = "\n".join(turns)dataset_pool["multiturn"].append({"raw_multiturn": all_text, "n_turns": len(turns)})count += 1if count >= 70000:breakprint(f" • Loaded {count:,} curated UltraChat multi-turn sequences.")except Exception as e:print(f" ⚠️ UltraChat-200k note: {e}")102 unmodified linesprint("\n📥 [7/8] Ingesting Domain 7: Basic Reasoning (HellaSwag 25k)...")try:hella_ds = load_dataset("Rowan/hellaswag", split="train")count = 0for row in hella_ds:ctx = clean_text(row["ctx"])endings = row["endings"]3 unmodified linesresp = correct_endif prompt and resp:dataset_pool["reasoning"].append({"instruction": prompt, "response": resp})count += 1if count >= 25000:breakprint(f" • Loaded {count:,} HellaSwag commonsense logic tasks.")except Exception as e:print(f" ⚠️ HellaSwag note: {e}")print(f" ✅ Domain 7 (Basic Reasoning): Total {len(dataset_pool['reasoning']):,} samples loaded.")# ------------------------------------------------------------------------------# DOMAIN 8: TRANSLATION (~50,000)# ------------------------------------------------------------------------------print("\n📥 [8/8] Ingesting Domain 8: Translation (IITB 150,000 raw pairs)...")try:iitb_ds = load_dataset("cfilt/iitb-english-hindi", split="train")count = 0for row in iitb_ds:en_txt = clean_text(row["translation"]["en"])hi_txt = clean_text(row["translation"]["hi"])5 unmodified linesq = f"Translate the following Hindi sentence to English:\n\"{hi_txt}\""ans = en_txtdataset_pool["translation"].append({"instruction": q, "response": ans})count += 1if count >= 150000:breakprint(f" • Loaded {count:,} raw IITB translation pairs.")except Exception as e:print(f" ⚠️ IITB Translation note: {e}")20 unmodified linesfinal_domain_counts = defaultdict(int)print("\n" + "=" * 85)print("📦 Compiling & Tokenizing SFT v14 Dataset (~380K+ Clean Scale)...")print("=" * 85)for dname, samples in dataset_pool.items():72 unmodified linesfinal_domain_counts[dname] += 1print("\n" + "=" * 85)print(f"📊 SFT v14 Master Dataset Compiled:")print(f" • Total Unique Samples: {len(all_compiled_samples):,}")print(f" • Total Duplicates Filtered: {total_pruned:,}")print(f" • Vocab Size: {actual_vocab_size}")49 unmodified lines# --- 7. Save Metadata ---meta = {"version": "sft_v14_master_hf_scale","created_at": datetime.now(timezone.utc).isoformat(),"total_samples": len(all_compiled_samples),"train_samples": len(train_samples),48 unmodified linesprint(f"\n❌ HF Upload Error: {e}")print("\n" + "=" * 85)print("✅ SFT v14 DATASET BUILD COMPLETE (~380K+ SCALE)!")print("=" * 85)123456789101112131415161718192021222324252627282932 unmodified lines62636465666768105 unmodified lines1741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162174 unmodified lines2222232242252262272281 unmodified line2302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972981 unmodified line30030130230330430530630730830931031131234 unmodified lines34734834935035135213 unmodified lines36636736836937037118 unmodified lines3903913923933943953963973983994004014021 unmodified line4044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424435 unmodified lines4494504514524534544554564574584594604617 unmodified lines469470471472473474475476477478102 unmodified lines5815825835845855865873 unmodified lines5915925935945955965975985996006016026036046056066076086096106116125 unmodified lines61861962062162262362462562662720 unmodified lines64864965065165265365472 unmodified lines72772872973073173273349 unmodified lines78378478578678778878948 unmodified lines838839840841842# ==============================================================================# ViuAI Sarus-500M — SFT v14 Master Dataset Builder (~385K+ Scale with 38% Hindi)# ==============================================================================# 100% READYMADE HUGGING FACE DATASETS ONLY — ZERO SYNTHETIC MULTIPLIERS.# ZERO PERSONA FILES. ZERO NOISY LOCAL FILES.## Heavy Hindi Reinforcement (~145k Total Hindi/Bilingual Content):# - sarvamai/samvaad-hi-v1 (35k pure natural Hindi dialogues)# - FreedomIntelligence/alpaca-gpt4-hindi (25k pure Hindi instructions)# - midas/m-dolly-15k-hi (15k human Hindi instructions)# - cfilt/iitb-english-hindi (200k raw -> ~60k deduplicated bilingual pairs)## 9 Balanced Domains:# 0. Conversational QA (~150k) — Samvaad Hindi, OpenHermes-2.5, OpenOrca, Alpaca Hindi, Dolly Hindi/Eng# 1. General Knowledge (~35k) — MMLU (57 subjects), ARC (Easy+Challenge), OpenBookQA# 2. Stories & Creative (~35k) — TinyStories (20k), Grammarly CoEdit (10k), WritingPrompts (5k)# 3. Multi-Turn (~60k) — UltraChat-200k (70k raw multi-turn sequences)# 4. Identity (~2.2k) — export_Identity_all.json (Sarus by ViuAI)# 5. Basic Math (~15k) — GSM8K (easy) + Orca Math (short word problems)# 6. Basic Coding (~25k) — CodeAlpaca-20k + Python Instructions 18k# 7. Basic Reasoning (~20k) — HellaSwag (25k clean reasoning scenarios)# 8. Translation (~60k) — IITB English-Hindi (200k raw -> ~60k deduplicated)## Vocab Size: 64,003 (Base 64,000 + <|user|> + <|assistant|> + <|endofturn|>)# Format: 100% Direct Response — no [THINK], no RAG, no persona# Target Scale: ~385,000+ Pristine Unique Samples (38% Hindi representation)# ==============================================================================import sys32 unmodified linesapi = HfApi(token=HF_TOKEN)print("=" * 85)print("🚀 SFT v14 Master Dataset Builder (~385K+ Scale | 38% Strong Hindi Reinforcement)")print(" ZERO Custom Local Data | ZERO Persona Files | ZERO Synthetic Multipliers")print(" Vocab: 64,003 | Format: 100% Direct Response")print("=" * 85)105 unmodified linesreturn False# ==============================================================================# --- 3. INGESTION — 9 BALANCED DOMAINS WITH HIGH HINDI REPRESENTATION ---# ==============================================================================dataset_pool = defaultdict(list)# ------------------------------------------------------------------------------# DOMAIN 0: CONVERSATIONAL QA (~150,000) — Heavy Hindi + English# ------------------------------------------------------------------------------print("\n📥 [0/8] Ingesting Domain 0: Conversational QA (Sarvam Samvaad Hindi, Alpaca Hindi, OpenHermes, OpenOrca)...")# 1. Sarvam AI: samvaad-hi-v1 (~35,000 Pure Natural Hindi Dialogues)try:samvaad_ds = load_dataset("sarvamai/samvaad-hi-v1", split="train", streaming=True)count_sam = 0for row in samvaad_ds:convs = row.get("conversations", row.get("dialogue", []))if isinstance(convs, list) and len(convs) >= 2:inst = clean_text(convs[0].get("value", convs[0].get("text", "")))resp = clean_text(convs[1].get("value", convs[1].get("text", "")))if inst and resp and 15 < len(resp) < 2000:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count_sam += 1elif "instruction" in row and "output" in row:inst = clean_text(row["instruction"])resp = clean_text(row["output"])if inst and resp and 15 < len(resp) < 2000:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count_sam += 1if count_sam >= 35000:breakprint(f" • 🇮🇳 Loaded {count_sam:,} Sarvam AI (Samvaad Hindi) natural conversations.")except Exception as e:print(f" ⚠️ Sarvam Samvaad note: {e}")# 2. FreedomIntelligence/alpaca-gpt4-hindi (~25,000 Pure Hindi)try:hindi_ds = load_dataset("FreedomIntelligence/alpaca-gpt4-hindi", split="train")count_hi = 0for row in hindi_ds:if "conversations" in row and isinstance(row["conversations"], list):inst, resp = "", ""4 unmodified linesresp = clean_text(turn.get("value", ""))if inst and resp and len(resp) < 2000:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count_hi += 1else:inst = clean_text(row.get("instruction", row.get("prompt", "")))inp = clean_text(row.get("input", ""))1 unmodified linefull_inst = f"{inst}\n{inp}".strip() if inp else instif full_inst and out and len(out) < 2000:dataset_pool["conversational"].append({"instruction": full_inst, "response": out})count_hi += 1if count_hi >= 25000:breakprint(f" • 🇮🇳 Loaded {count_hi:,} Alpaca GPT-4 Hindi instruction tasks.")except Exception as e:print(f" ⚠️ Hindi Alpaca note: {e}")# 3. midas/m-dolly-15k-hi (15,000 Hindi Dolly)try:dolly_hi = load_dataset("midas/m-dolly-15k-hi", split="train")count_dhi = 0for row in dolly_hi:inst = clean_text(row.get("instruction", ""))ctx = clean_text(row.get("context", ""))resp = clean_text(row.get("response", ""))full_inst = f"{inst}\nसंदर्भ:\n{ctx}" if ctx else instif full_inst and resp and len(resp) < 2000:dataset_pool["conversational"].append({"instruction": full_inst, "response": resp})count_dhi += 1print(f" • 🇮🇳 Loaded {count_dhi:,} M-Dolly Hindi human instructions.")except Exception as e:print(f" ⚠️ M-Dolly Hindi fallback: {e}")# 4. OpenHermes-2.5 (~60,000 English)try:hermes_ds = load_dataset("teknium/OpenHermes-2.5", split="train", streaming=True)count_herm = 0for row in hermes_ds:convs = row.get("conversations", [])if len(convs) >= 2:inst = clean_text(convs[0].get("value", ""))resp = clean_text(convs[1].get("value", ""))if inst and resp and 15 < len(resp) < 1800 and len(inst) > 8:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count_herm += 1if count_herm >= 60000:breakprint(f" • Loaded {count_herm:,} OpenHermes-2.5 conversations.")except Exception as e:print(f" ⚠️ OpenHermes note: {e}")# 5. Open-Orca (~25,000 English)try:orca_ds = load_dataset("Open-Orca/OpenOrca", split="train", streaming=True)count_orc = 0for row in orca_ds:inst = clean_text(row.get("question", ""))resp = clean_text(row.get("response", ""))sys_p = clean_text(row.get("system_prompt", ""))full_inst = f"{sys_p}\n\n{inst}".strip() if sys_p and len(sys_p) < 300 else instif full_inst and resp and 15 < len(resp) < 1500:dataset_pool["conversational"].append({"instruction": full_inst, "response": resp})count_orc += 1if count_orc >= 25000:breakprint(f" • Loaded {count_orc:,} OpenOrca instruction pairs.")except Exception as e:print(f" ⚠️ OpenOrca note: {e}")# 6. tatsu-lab/alpaca (~25,000 English)try:alpaca_ds = load_dataset("tatsu-lab/alpaca", split="train")count_alp = 0for row in alpaca_ds:inst = clean_text(row.get("instruction", ""))inp = clean_text(row.get("input", ""))1 unmodified linefull_inst = f"{inst}\n{inp}".strip() if inp else instif full_inst and out and len(out) < 1500:dataset_pool["conversational"].append({"instruction": full_inst, "response": out})count_alp += 1if count_alp >= 25000:breakprint(f" • Loaded {count_alp:,} Alpaca-52k instructions.")except Exception as e:print(f" ⚠️ Alpaca note: {e}")print(f" ✅ Domain 0 (Conversational QA): Total {len(dataset_pool['conversational']):,} raw samples loaded.")# ------------------------------------------------------------------------------34 unmodified linesbreakprint(f" • Loaded {count_mmlu:,} MMLU academic QA pairs.")count_arc = 0for arc_type in ["ARC-Easy", "ARC-Challenge"]:try:13 unmodified linespassprint(f" • Loaded {count_arc:,} ARC science questions.")try:obqa_ds = load_dataset("openbookqa", "main", split="train")count_ob = 018 unmodified linesprint(f" ✅ Domain 1 (General Knowledge): Total {len(dataset_pool['gk']):,} raw samples loaded.")# ------------------------------------------------------------------------------# DOMAIN 2: STORIES & CREATIVE WRITING (~35,000)# ------------------------------------------------------------------------------print("\n📥 [2/8] Ingesting Domain 2: Stories & Creative Writing (TinyStories 20k + Grammarly CoEdit 10k + WritingPrompts)...")try:ts_ds = load_dataset("roneneldan/TinyStories", split="train", streaming=True)count_ts = 0for row in ts_ds:story_text = clean_text(row.get("text", ""))if story_text and 100 < len(story_text) < 1500:1 unmodified linefirst_line = lines[0].strip()prompt = f"Write a short, engaging story with a meaningful theme:\n\"{first_line[:120]}\""dataset_pool["stories"].append({"instruction": prompt, "response": story_text})count_ts += 1if count_ts >= 20000:breakprint(f" • Loaded {count_ts:,} TinyStories creative narratives.")except Exception as e:print(f" ⚠️ TinyStories note: {e}")try:coedit_ds = load_dataset("grammarly/coedit", split="train")count_co = 0for row in coedit_ds:src = clean_text(row["src"])tgt = clean_text(row["tgt"])if src and tgt and len(src) < 1000:dataset_pool["stories"].append({"instruction": src, "response": tgt})count_co += 1if count_co >= 10000:breakprint(f" • Loaded {count_co:,} Grammarly text rewrites.")except Exception as e:print(f" ⚠️ CoEdit note: {e}")try:wp_ds = load_dataset("euclaise/writingprompts", split="train", streaming=True)count_wp = 0for row in wp_ds:p = clean_text(row.get("prompt", ""))s = clean_text(row.get("story", ""))if p and s and 80 < len(s) < 1500 and len(p) > 10:dataset_pool["stories"].append({"instruction": f"Write a short story based on this prompt:\n{p}", "response": s})count_wp += 1if count_wp >= 5000:breakprint(f" • Loaded {count_wp:,} WritingPrompts creative stories.")except Exception as e:print(f" ⚠️ WritingPrompts note: {e}")5 unmodified linesprint("\n📥 [3/8] Ingesting Domain 3: Multi-Turn Conversations (UltraChat 200k)...")try:ultra_ds = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft", streaming=True)count_ult = 0for row in ultra_ds:messages = row.get("messages", [])if isinstance(messages, list) and 4 <= len(messages) <= 8:turns = []valid = Truefor i, msg in enumerate(messages[:6]):content = clean_text(msg.get("content", ""))role = msg.get("role", "")if not content or len(content) > 1200:7 unmodified linesif valid and len(turns) >= 4:all_text = "\n".join(turns)dataset_pool["multiturn"].append({"raw_multiturn": all_text, "n_turns": len(turns)})count_ult += 1if count_ult >= 70000:breakprint(f" • Loaded {count_ult:,} curated UltraChat multi-turn sequences.")except Exception as e:print(f" ⚠️ UltraChat-200k note: {e}")102 unmodified linesprint("\n📥 [7/8] Ingesting Domain 7: Basic Reasoning (HellaSwag 25k)...")try:hella_ds = load_dataset("Rowan/hellaswag", split="train")count_hel = 0for row in hella_ds:ctx = clean_text(row["ctx"])endings = row["endings"]3 unmodified linesresp = correct_endif prompt and resp:dataset_pool["reasoning"].append({"instruction": prompt, "response": resp})count_hel += 1if count_hel >= 25000:breakprint(f" • Loaded {count_hel:,} HellaSwag commonsense logic tasks.")except Exception as e:print(f" ⚠️ HellaSwag note: {e}")print(f" ✅ Domain 7 (Basic Reasoning): Total {len(dataset_pool['reasoning']):,} samples loaded.")# ------------------------------------------------------------------------------# DOMAIN 8: TRANSLATION (~60,000)# ------------------------------------------------------------------------------print("\n📥 [8/8] Ingesting Domain 8: Translation (IITB 200,000 raw pairs)...")try:iitb_ds = load_dataset("cfilt/iitb-english-hindi", split="train")count_tr = 0for row in iitb_ds:en_txt = clean_text(row["translation"]["en"])hi_txt = clean_text(row["translation"]["hi"])5 unmodified linesq = f"Translate the following Hindi sentence to English:\n\"{hi_txt}\""ans = en_txtdataset_pool["translation"].append({"instruction": q, "response": ans})count_tr += 1if count_tr >= 200000:breakprint(f" • 🇮🇳 Loaded {count_tr:,} raw IITB translation pairs.")except Exception as e:print(f" ⚠️ IITB Translation note: {e}")20 unmodified linesfinal_domain_counts = defaultdict(int)print("\n" + "=" * 85)print("📦 Compiling & Tokenizing SFT v14 Dataset (~385K+ Scale with 38% Hindi)...")print("=" * 85)for dname, samples in dataset_pool.items():72 unmodified linesfinal_domain_counts[dname] += 1print("\n" + "=" * 85)print(f"📊 SFT v14 Master Dataset Compiled (Heavy Hindi Scale):")print(f" • Total Unique Samples: {len(all_compiled_samples):,}")print(f" • Total Duplicates Filtered: {total_pruned:,}")print(f" • Vocab Size: {actual_vocab_size}")49 unmodified lines# --- 7. Save Metadata ---meta = {"version": "sft_v14_master_hindi_scale","created_at": datetime.now(timezone.utc).isoformat(),"total_samples": len(all_compiled_samples),"train_samples": len(train_samples),48 unmodified linesprint(f"\n❌ HF Upload Error: {e}")print("\n" + "=" * 85)print("✅ SFT v14 DATASET BUILD COMPLETE (~385K+ SCALE | 38% HINDI REINFORCED)!")print("=" * 85)
code/build_sft_v14_dataset.py+132-107