Upload code/build_sft_v17_dataset.py with huggingface_hub
Browse files36 unmodified lines37383940414243444518 unmodified lines646566676869707172525 unmodified lines5985996006016026036044 unmodified lines6096106116126136146155 unmodified lines6216226236246256266276286296306316326336348 unmodified lines6436446456466476486493 unmodified lines6536546556566576586599 unmodified lines66967067167267367467517 unmodified lines69369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572636 unmodified linesVAL_RATIO = 0.02SEED = 42# Strict Target Cap per Major Domain for 100% Equal Balance (~152k Total)DOMAIN_TARGET_CAP = 16500IDENTITY_TARGET_CAP = 3500random.seed(SEED)np.random.seed(SEED)18 unmodified lines"identity_greetings": 9}print("=" * 85)print(f"🚀 ViuAI Sarus-500M — SFT {VERSION.upper()} Super Master Dataset Builder (150k+ Scale)")print(f" ⚖️ Equal Balance: ~{DOMAIN_TARGET_CAP:,} per core domain | JSON | NCERT | Summarize | Anti-Hallucination")print("=" * 85)525 unmodified lineswith open(id_path, "r", encoding="utf-8") as f:id_data = json.load(f)for row in id_data:if len(domain_pools["identity_greetings"]) >= IDENTITY_TARGET_CAP:breakadd_sample("identity_greetings", row.get("instruction", ""), row.get("thinking", "Identify as Sarus created by ViuAI, friendly and warm persona."), row.get("response", ""))print(f" ✅ [identity_greetings] : {len(domain_pools['identity_greetings']):,} loaded")4 unmodified linescc_data = json.load(f)random.shuffle(cc_data)for row in cc_data:if len(domain_pools["empathetic_chitchat"]) >= DOMAIN_TARGET_CAP:breakresp = row.get("response", "")if "mom" in resp.lower():5 unmodified lineswith open(math_path, "r", encoding="utf-8") as f:math_data = json.load(f)for row in math_data:if len(domain_pools["math_logic"]) >= DOMAIN_TARGET_CAP:breakadd_sample("math_logic", row.get("instruction", ""), row.get("thinking", "Mathematical analysis and logical step calculation."), row.get("response", ""))try:gsm = load_dataset("openai/gsm8k", "main", split="train")for r in gsm:if len(domain_pools["math_logic"]) >= DOMAIN_TARGET_CAP:breakq = r.get("question", "").strip()a = r.get("answer", "").strip()8 unmodified lineswith open(reason_path, "r", encoding="utf-8") as f:reason_data = json.load(f)for row in reason_data:if len(domain_pools["reasoning_domain"]) >= DOMAIN_TARGET_CAP:breakadd_sample("reasoning_domain", row.get("instruction", ""), row.get("thinking", "Logical reasoning and step-by-step premise deduction."), row.get("response", ""))3 unmodified linescode_samples = list(code_ds)random.shuffle(code_samples)for r in code_samples:if len(domain_pools["coding_tech"]) >= DOMAIN_TARGET_CAP:breakinst = r.get("instruction", "").strip()inp = r.get("input", "").strip()9 unmodified linestry:samvaad = load_dataset("gairik/samvaad-hi-v1", split="train")for r in samvaad:if len(domain_pools["gk_polity_history"]) >= DOMAIN_TARGET_CAP:breakinst = r.get("instruction", "").strip()out = r.get("output", "").strip()17 unmodified linesif not inst or not resp:continueif {"translation", "translate", "trans"}.intersection(cat_words) and len(domain_pools["translation_multilingual"]) < DOMAIN_TARGET_CAP:add_sample("translation_multilingual", inst, th or "Direct 1-to-1 language translation.", resp)elif {"career", "resume", "cv", "interview", "job", "cover_letter", "email", "resignation", "workplace", "professional"}.intersection(cat_words) and len(domain_pools["career_productivity"]) < DOMAIN_TARGET_CAP:add_sample("career_productivity", inst, th or "Professional formatting and clear writing structure.", resp)elif {"puzzle", "riddle", "reason", "reasoning", "logic", "deduction"}.intersection(cat_words) and len(domain_pools["reasoning_domain"]) < DOMAIN_TARGET_CAP:add_sample("reasoning_domain", inst, th or "Logical analysis of relation and puzzle constraints.", resp)elif {"recipe", "food", "cook", "chai", "kitchen", "cooking", "dish", "cuisine"}.intersection(cat_words) and len(domain_pools["recipes_indian_utility"]) < DOMAIN_TARGET_CAP:if "chai" in inst.lower() and ("batter" in resp.lower() or "fridge" in resp.lower()):continueadd_sample("recipes_indian_utility", inst, th or "Authentic step-by-step cooking recipe with exact kitchen ingredients.", resp)elif {"finance", "health", "wellness", "fitness", "money", "diet", "nutrition", "workout", "tax", "investing"}.intersection(cat_words) and len(domain_pools["finance_health_wellness"]) < DOMAIN_TARGET_CAP:add_sample("finance_health_wellness", inst, th or "Health and financial well-being advice.", resp)elif {"math", "calc", "algebra", "arithmetic", "geometry", "calculus"}.intersection(cat_words) and len(domain_pools["math_logic"]) < DOMAIN_TARGET_CAP:add_sample("math_logic", inst, th or "Step-by-step mathematical reasoning.", resp)# Final Strict Truncationmaster_pool = []print("\n--- Final Strictly Balanced Equal-Share Domain Counts ---")for d, items in domain_pools.items():random.shuffle(items)cap = IDENTITY_TARGET_CAP if d == "identity_greetings" else DOMAIN_TARGET_CAPfinal_items = items[:cap]domain_pools[d] = final_itemsmaster_pool.extend(final_items)pct = (len(final_items) / max(1, (9 * DOMAIN_TARGET_CAP + IDENTITY_TARGET_CAP))) * 100print(f" • {d:<25}: {len(final_items):>6,} samples ({pct:.1f}%)")print(f"\n🎉 Total Strictly Balanced Master Pool: {len(master_pool):,} Samples!")return master_pool36 unmodified lines3738394041424344454647484950515253545518 unmodified lines7475767778798081828384525 unmodified lines6106116126136146156164 unmodified lines6216226236246256266275 unmodified lines6336346356366376386396406416426436446456468 unmodified lines6556566576586596606613 unmodified lines6656666676686696706719 unmodified lines68168268368468568668717 unmodified lines70570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773836 unmodified linesVAL_RATIO = 0.02SEED = 42# Strategic Target Caps tailored for 500M SLM (~164k Total Scale)DOMAIN_TARGET_CAPS = {"coding_tech": 18500, # High syntax complexity & algorithms (+2k boost)"math_logic": 18500, # Step-by-step arithmetic reasoning (+2k boost)"reasoning_domain": 18500, # Logic puzzles & anti-hallucination (+2k boost)"empathetic_chitchat": 18500, # Conversational Hinglish & creative (+2k boost)"gk_polity_history": 18500, # Samvaad + NCERT Science + Modern GK (+2k boost)"career_productivity": 17000, # Workplace, Summarization & JSON (+500 boost)"recipes_indian_utility": 17000, # Indian kitchen & cooking (+500 boost)"finance_health_wellness": 17000,# Daily health & finance (+500 boost)"translation_multilingual": 17000,# 1-to-1 parallel translation (+500 boost)"identity_greetings": 3500 # Pure ViuAI Sarus persona anchors}random.seed(SEED)np.random.seed(SEED)18 unmodified lines"identity_greetings": 9}TOTAL_PLANNED = sum(DOMAIN_TARGET_CAPS.values())print("=" * 85)print(f"🚀 ViuAI Sarus-500M — SFT {VERSION.upper()} Super Master Dataset Builder ({TOTAL_PLANNED:,} Scale)")print(f" ⚖️ Strategic Cognitive Balance | Coding: 18.5k | Math: 18.5k | Reasoning: 18.5k | NCERT & JSON")print("=" * 85)525 unmodified lineswith open(id_path, "r", encoding="utf-8") as f:id_data = json.load(f)for row in id_data:if len(domain_pools["identity_greetings"]) >= DOMAIN_TARGET_CAPS["identity_greetings"]:breakadd_sample("identity_greetings", row.get("instruction", ""), row.get("thinking", "Identify as Sarus created by ViuAI, friendly and warm persona."), row.get("response", ""))print(f" ✅ [identity_greetings] : {len(domain_pools['identity_greetings']):,} loaded")4 unmodified linescc_data = json.load(f)random.shuffle(cc_data)for row in cc_data:if len(domain_pools["empathetic_chitchat"]) >= DOMAIN_TARGET_CAPS["empathetic_chitchat"]:breakresp = row.get("response", "")if "mom" in resp.lower():5 unmodified lineswith open(math_path, "r", encoding="utf-8") as f:math_data = json.load(f)for row in math_data:if len(domain_pools["math_logic"]) >= DOMAIN_TARGET_CAPS["math_logic"]:breakadd_sample("math_logic", row.get("instruction", ""), row.get("thinking", "Mathematical analysis and logical step calculation."), row.get("response", ""))try:gsm = load_dataset("openai/gsm8k", "main", split="train")for r in gsm:if len(domain_pools["math_logic"]) >= DOMAIN_TARGET_CAPS["math_logic"]:breakq = r.get("question", "").strip()a = r.get("answer", "").strip()8 unmodified lineswith open(reason_path, "r", encoding="utf-8") as f:reason_data = json.load(f)for row in reason_data:if len(domain_pools["reasoning_domain"]) >= DOMAIN_TARGET_CAPS["reasoning_domain"]:breakadd_sample("reasoning_domain", row.get("instruction", ""), row.get("thinking", "Logical reasoning and step-by-step premise deduction."), row.get("response", ""))3 unmodified linescode_samples = list(code_ds)random.shuffle(code_samples)for r in code_samples:if len(domain_pools["coding_tech"]) >= DOMAIN_TARGET_CAPS["coding_tech"]:breakinst = r.get("instruction", "").strip()inp = r.get("input", "").strip()9 unmodified linestry:samvaad = load_dataset("gairik/samvaad-hi-v1", split="train")for r in samvaad:if len(domain_pools["gk_polity_history"]) >= DOMAIN_TARGET_CAPS["gk_polity_history"]:breakinst = r.get("instruction", "").strip()out = r.get("output", "").strip()17 unmodified linesif not inst or not resp:continueif {"translation", "translate", "trans"}.intersection(cat_words) and len(domain_pools["translation_multilingual"]) < DOMAIN_TARGET_CAPS["translation_multilingual"]:add_sample("translation_multilingual", inst, th or "Direct 1-to-1 language translation.", resp)elif {"career", "resume", "cv", "interview", "job", "cover_letter", "email", "resignation", "workplace", "professional"}.intersection(cat_words) and len(domain_pools["career_productivity"]) < DOMAIN_TARGET_CAPS["career_productivity"]:add_sample("career_productivity", inst, th or "Professional formatting and clear writing structure.", resp)elif {"puzzle", "riddle", "reason", "reasoning", "logic", "deduction"}.intersection(cat_words) and len(domain_pools["reasoning_domain"]) < DOMAIN_TARGET_CAPS["reasoning_domain"]:add_sample("reasoning_domain", inst, th or "Logical analysis of relation and puzzle constraints.", resp)elif {"recipe", "food", "cook", "chai", "kitchen", "cooking", "dish", "cuisine"}.intersection(cat_words) and len(domain_pools["recipes_indian_utility"]) < DOMAIN_TARGET_CAPS["recipes_indian_utility"]:if "chai" in inst.lower() and ("batter" in resp.lower() or "fridge" in resp.lower()):continueadd_sample("recipes_indian_utility", inst, th or "Authentic step-by-step cooking recipe with exact kitchen ingredients.", resp)elif {"finance", "health", "wellness", "fitness", "money", "diet", "nutrition", "workout", "tax", "investing"}.intersection(cat_words) and len(domain_pools["finance_health_wellness"]) < DOMAIN_TARGET_CAPS["finance_health_wellness"]:add_sample("finance_health_wellness", inst, th or "Health and financial well-being advice.", resp)elif {"math", "calc", "algebra", "arithmetic", "geometry", "calculus"}.intersection(cat_words) and len(domain_pools["math_logic"]) < DOMAIN_TARGET_CAPS["math_logic"]:add_sample("math_logic", inst, th or "Step-by-step mathematical reasoning.", resp)# Final Strategic Truncationmaster_pool = []print("\n--- Final Strategic Cognitive Domain Distribution ---")for d, items in domain_pools.items():random.shuffle(items)cap = DOMAIN_TARGET_CAPS.get(d, 17000)final_items = items[:cap]domain_pools[d] = final_itemsmaster_pool.extend(final_items)pct = (len(final_items) / max(1, TOTAL_PLANNED)) * 100print(f" • {d:<25}: {len(final_items):>6,} samples ({pct:.1f}%)")print(f"\n🎉 Total Strategic Master Pool: {len(master_pool):,} Samples!")return master_pool
code/build_sft_v17_dataset.py+35-23