Upload code/build_sft_v18_dataset.py with huggingface_hub
Browse files130 unmodified lines131132133134135136137138139140141143 unmodified lines28528628728828929029129229329429529629729829930030130230318 unmodified lines322323324325326327328552 unmodified lines881882883884885886887130 unmodified linesreturn f"Solve the mathematical problem step-by-step: extract given parameters, state clear formulas, compute arithmetic, verify final answer."elif domain == "translation_multilingual":if "to hindi" in inst_lower or "hindi anuvaad" in inst_lower:return "Translate accurately from English to Hindi, preserving natural nuances and correct grammar."elif "to english" in inst_lower:return "Translate accurately from Hindi to English, ensuring fluent and natural phrasing."return "Provide natural, accurate translation matching the tone and context of the source text."elif domain == "gk_polity_history":return "Recall accurate historical facts, constitutional articles, and scientific details clearly and objectively."143 unmodified linesreturn samplesdef ingest_iitb_translations(target_count=16500) -> list:"""Ingests 100% real English <-> Hindi parallel sentences from cfilt/iitb-english-hindi."""print(f"⬇️ Ingesting IITB English-Hindi Translations (Target: {target_count:,} unique)...")samples = []try:ds = load_dataset("cfilt/iitb-english-hindi", split="train", streaming=True)count = 0for row in ds:tr = row.get("translation", {})eng = tr.get("en", "").strip()hin = tr.get("hi", "").strip()if not eng or not hin or len(eng) < 15 or len(hin) < 15 or len(eng) > 400:continue# Alternate between English -> Hindi and Hindi -> English18 unmodified linesif len(samples) >= target_count:breakexcept Exception as e:print(f" ⚠️ Error loading IITB translation: {e}")print(f" ✅ [translation_multilingual] Loaded: {len(samples):,} unique samples")return samples552 unmodified linesmaster_pool.extend(get_curated_identity_and_greetings_pack(DOMAIN_TARGET_CAPS["identity_greetings"]))master_pool.extend(ingest_codealpaca(DOMAIN_TARGET_CAPS["coding_tech"]))master_pool.extend(ingest_gsm8k_and_math(DOMAIN_TARGET_CAPS["math_logic"]))master_pool.extend(ingest_iitb_translations(DOMAIN_TARGET_CAPS["translation_multilingual"]))master_pool.extend(ingest_alpaca_gpt4_hindi(DOMAIN_TARGET_CAPS["gk_polity_history"]))master_pool.extend(ingest_career_and_productivity(DOMAIN_TARGET_CAPS["career_productivity"]))master_pool.extend(ingest_health_and_wellness(DOMAIN_TARGET_CAPS["finance_health_wellness"]))130 unmodified lines131132133134135136137138139140141142143143 unmodified lines28728828929029129229329429529629729829930030130230330430530630730830918 unmodified lines328329330331332333334552 unmodified lines887888889890891892893130 unmodified linesreturn f"Solve the mathematical problem step-by-step: extract given parameters, state clear formulas, compute arithmetic, verify final answer."elif domain == "translation_multilingual":words = [w for w in re.findall(r"\b[A-Za-z\u0900-\u097F]{4,}\b", instruction) if w.lower() not in ["translate", "following", "sentence", "hindi", "english", "anuvaad"]]key_terms = words[:3]terms_str = f"such as '{', '.join(key_terms)}'" if key_terms else "in context"if "to hindi" in inst_lower or "hindi" in inst_lower:return f"The user wants an accurate English-to-Hindi translation. Analyze the context and tone. Translate key vocabulary {terms_str} into natural Hindi equivalents. Structure the Hindi output in proper Subject-Object-Verb order for fluent, idiomatic Devanagari phrasing."else:return f"The user wants an accurate Hindi-to-English translation. Analyze the sentence intent and key concepts {terms_str}. Structure the English translation with proper Subject-Verb-Object syntax and clear, contemporary phrasing."elif domain == "gk_polity_history":return "Recall accurate historical facts, constitutional articles, and scientific details clearly and objectively."143 unmodified linesreturn samplesdef ingest_ai4bharat_translations(target_count=16500) -> list:"""Ingests 100% natural, high-quality English <-> Hindi parallel sentences from ai4bharat/samanantar."""print(f"⬇️ Ingesting AI4Bharat Samanantar Natural Translations (Target: {target_count:,} unique)...")samples = []try:ds = load_dataset("ai4bharat/samanantar", "hi", split="train", streaming=True)count = 0for row in ds:eng = row.get("src", "").strip()hin = row.get("tgt", "").strip()# Strict quality filter: Clean natural human sentences, no software UI or garbageif not eng or not hin or len(eng) < 25 or len(hin) < 25 or len(eng) > 220 or len(hin) > 220:continueif any(c in eng for c in ["<", ">", "{", "}", "%", "/", "\\", "$", "#", "@", "|", "_"]):continueif any(w in eng.lower() for w in ["http", "www", "plugin", "gnome", "linux", "ubuntu", "xml", "copyright", "dialog"]):continue# Alternate between English -> Hindi and Hindi -> English18 unmodified linesif len(samples) >= target_count:breakexcept Exception as e:print(f" ⚠️ Error loading AI4Bharat Samanantar translation: {e}")print(f" ✅ [translation_multilingual] Loaded: {len(samples):,} unique samples")return samples552 unmodified linesmaster_pool.extend(get_curated_identity_and_greetings_pack(DOMAIN_TARGET_CAPS["identity_greetings"]))master_pool.extend(ingest_codealpaca(DOMAIN_TARGET_CAPS["coding_tech"]))master_pool.extend(ingest_gsm8k_and_math(DOMAIN_TARGET_CAPS["math_logic"]))master_pool.extend(ingest_ai4bharat_translations(DOMAIN_TARGET_CAPS["translation_multilingual"]))master_pool.extend(ingest_alpaca_gpt4_hindi(DOMAIN_TARGET_CAPS["gk_polity_history"]))master_pool.extend(ingest_career_and_productivity(DOMAIN_TARGET_CAPS["career_productivity"]))master_pool.extend(ingest_health_and_wellness(DOMAIN_TARGET_CAPS["finance_health_wellness"]))
code/build_sft_v18_dataset.py+21-15