Upload code/build_sft_v14_dataset.py with huggingface_hub
Browse files188 unmodified lines18919019119219319419519619719838 unmodified lines237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276188 unmodified linessamvaad_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 += 138 unmodified linesexcept Exception as e:print(f" ⚠️ Hindi Alpaca note: {e}")# 3. ai4bharat/indic-instruct-data-v0.1 (~20,000 Hindi Instructions)try:indic_ds = load_dataset("ai4bharat/indic-instruct-data-v0.1", "hi", split="train", streaming=True)count_ind = 0for row in indic_ds:inst = clean_text(row.get("native_instruction", row.get("instruction", "")))inp = clean_text(row.get("native_input", row.get("input", "")))out = clean_text(row.get("native_output", row.get("output", "")))full_inst = f"{inst}\n{inp}".strip() if inp else instif full_inst and out and 15 < len(out) < 2000:dataset_pool["conversational"].append({"instruction": full_inst, "response": out})count_ind += 1if count_ind >= 20000:breakprint(f" • 🇮🇳 Loaded {count_ind:,} AI4Bharat Indic-Instruct Hindi tasks.")except Exception as e:print(f" ⚠️ AI4Bharat Indic-Instruct note: {e}")# 4. 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)188 unmodified lines18919019119219319419519619719819920020120238 unmodified lines241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270188 unmodified linessamvaad_ds = load_dataset("sarvamai/samvaad-hi-v1", split="train", streaming=True)count_sam = 0for row in samvaad_ds:msgs = row.get("messages", row.get("conversations", []))if isinstance(msgs, list) and len(msgs) >= 2:inst, resp = "", ""for turn in msgs:if turn.get("role") in ["user", "human"]:inst = clean_text(turn.get("content", turn.get("value", "")))elif turn.get("role") in ["assistant", "gpt"]:resp = clean_text(turn.get("content", turn.get("value", "")))if inst and resp and 15 < len(resp) < 2000:dataset_pool["conversational"].append({"instruction": inst, "response": resp})count_sam += 138 unmodified linesexcept Exception as e:print(f" ⚠️ Hindi Alpaca note: {e}")# 3. AI4Bharat Indic-Instruct: 'dolly' and 'anudesh' on split='hi' (~25,000 Hindi Tasks)try:count_ind = 0for subset in ["dolly", "anudesh", "flan_v2"]:try:indic_ds = load_dataset("ai4bharat/indic-instruct-data-v0.1", subset, split="hi", streaming=True)for row in indic_ds:inst = clean_text(row.get("native_instruction", row.get("instruction", "")))inp = clean_text(row.get("native_input", row.get("input", "")))out = clean_text(row.get("native_output", row.get("output", row.get("response", ""))))full_inst = f"{inst}\n{inp}".strip() if inp else instif full_inst and out and 15 < len(out) < 2000:dataset_pool["conversational"].append({"instruction": full_inst, "response": out})count_ind += 1if count_ind >= 25000:breakexcept Exception:continueif count_ind >= 25000:breakprint(f" • 🇮🇳 Loaded {count_ind:,} AI4Bharat Indic-Instruct Hindi tasks.")except Exception as e:print(f" ⚠️ AI4Bharat Indic-Instruct note: {e}")# 4. OpenHermes-2.5 (~60,000 English)try:hermes_ds = load_dataset("teknium/OpenHermes-2.5", split="train", streaming=True)
code/build_sft_v14_dataset.py+25-31