ViuAI commited on
Commit
4e8045f
·
verified ·
1 Parent(s): e95b5f6

Update builder script: 9 domains, integrate user identity and greetings, remove safety

Browse files
Files changed (1) hide show
  1. code/build_sarus_sft_dataset_kaggle.py +65 -145
code/build_sarus_sft_dataset_kaggle.py CHANGED
@@ -47,7 +47,7 @@ EOT_TOKEN = "<|endofturn|>"
47
  PAD_TOKEN_ID = 64000
48
  EOT_ID = 64002
49
 
50
- # 10 Domain Architecture
51
  DOMAIN_NAMES = {
52
  0: "identity_sarus",
53
  1: "greetings_cultural",
@@ -57,27 +57,25 @@ DOMAIN_NAMES = {
57
  5: "general_stem",
58
  6: "hindi_culture",
59
  7: "summarization_translation",
60
- 8: "multiturn_dialogue",
61
- 9: "safety_refusal"
62
  }
63
 
64
- # Target Domain Budgets (~255,000 Total High-Purity Real Samples)
65
  DOMAIN_TARGETS = {
66
- 0: 5000, # Identity (Sarus / ViuAI)
67
- 1: 8000, # Cultural & Conversational Greetings
68
  2: 40000, # NCERT (Grades 9-12) & Indian History / Constitution
69
  3: 50000, # Coding & Tech (Python, Algorithms, SQL, Web)
70
  4: 30000, # Math & Arithmetic Reasoning (GSM8K + Mental Arithmetic)
71
  5: 35000, # General STEM & World Science (Stanford Alpaca)
72
  6: 35000, # Hindi Language, Culture & Society (Alpaca Hindi)
73
  7: 25000, # Summarization (DialogSum) & Translation (IITB)
74
- 8: 20000, # Multi-Turn Conversations (UltraChat)
75
- 9: 7000 # Safety & Ethical Refusals (Anthropic Harmless)
76
  }
77
 
78
  print("=" * 85)
79
  print("🌟 ViuAI Sarus-500M — SFT v1 Master Real-Data Builder & Dual-Uploader")
80
- print(" • Target Capacity: ~255,000 Samples across 10 Capability Domains")
81
  print(" • Model Identity: Sarus (सारस) | Developer: ViuAI")
82
  print(f" • Database 1 (Raw): {RAW_REPO_ID}")
83
  print(f" • Database 2 (NPY): {TOKENIZED_REPO_ID} [sft_v1]")
@@ -138,123 +136,70 @@ def clean_text(text: str) -> str:
138
  # ------------------------------------------------------------------------------
139
 
140
  # --- Domain 0: Identity (Sarus / ViuAI) ---
141
- def build_domain_identity(target=5000):
142
- print(f"\n[D0: Identity] Sourcing real identity queries grounded to Sarus (Target: {target:,})...")
143
  samples = []
144
-
145
- # Truthful Grounded Knowledge
146
- identity_en = (
147
- "My name is Sarus, an AI model developed by ViuAI. "
148
- "I am designed to assist you with programming, mathematics, science, reasoning, "
149
- "and bilingual conversations in Hindi and English with high precision and respect."
150
- )
151
- identity_hi = (
152
- "मेरा नाम सारस (Sarus) है। मुझे ViuAI द्वारा विकसित किया गया है। "
153
- "मैं कोडिंग, गणित, विज्ञान, तर्क और हिंदी-अंग्रेजी बातचीत में आपकी सहायता करने के लिए बनाया गया हूँ।"
154
- )
155
-
156
- # Real question variations from chat logs
157
- real_queries_en = [
158
- "Who created you?", "What is your name?", "Who are you?", "What model are you?",
159
- "Who developed you?", "Are you ChatGPT?", "Are you made by OpenAI?", "Tell me about yourself.",
160
- "What is your purpose and who made you?", "Are you an AI developed by Google?",
161
- "Can you introduce yourself?", "What are your capabilities and who built you?",
162
- "Which organization created you?", "What should I call you?", "Are you Claude or GPT?",
163
- "Explain your identity and origins."
164
- ]
165
- real_queries_hi = [
166
- "तुम्हारा नाम क्या है?", "आपको किसने बनाया है?", "आप कौन हैं?", "क्या आप ChatGPT हैं?",
167
- "क्या आपको OpenAI ने बनाया है?", "अपना परिचय दीजिए।", "आपका निर्माता कौन है?",
168
- "आप क्या-क्या कर सकते हैं और आपको किसने विकसित किया है?", "क्या आप गूगल के AI हैं?",
169
- "मुझे आपके बारे में जानना है।", "आपका उद्देश्य क्या है?", "आप किस कंपनी का मॉडल हैं?"
170
  ]
 
 
 
 
 
 
 
 
 
171
 
172
- for q in real_queries_en:
173
- samples.append({"instruction": q, "response": identity_en, "domain_id": 0})
174
- for q in real_queries_hi:
175
- samples.append({"instruction": q, "response": identity_hi, "domain_id": 0})
176
-
177
- # Stream real user identity questions from UltraChat / LMSYS
178
- try:
179
- ds = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft", streaming=True)
180
- for row in ds:
181
- msgs = row.get("messages", [])
182
- if len(msgs) >= 2:
183
- q = msgs[0].get("content", "").strip()
184
- if any(w in q.lower() for w in ["who are you", "what is your name", "who made you", "who created you", "your developer"]):
185
- if not is_duplicate(q):
186
- samples.append({"instruction": q, "response": identity_en, "domain_id": 0})
187
- if len(samples) >= target:
188
- break
189
- except Exception as e:
190
- print(f" ℹ️ UltraChat identity stream: {e}")
191
-
192
- # Top-up with bilingual variations if needed
193
- while len(samples) < target:
194
- for q in real_queries_en:
195
- samples.append({"instruction": f"Hello! {q}", "response": identity_en, "domain_id": 0})
196
- if len(samples) >= target:
197
- break
198
- for q in real_queries_hi:
199
- samples.append({"instruction": f"नमस्ते! {q}", "response": identity_hi, "domain_id": 0})
200
- if len(samples) >= target:
201
- break
202
-
203
- print(f" ✅ [D0: Identity] Ingested {len(samples):,} verified Sarus samples.")
204
  return samples[:target]
205
 
206
 
207
  # --- Domain 1: Greetings & Cultural Openers ---
208
- def build_domain_greetings(target=8000):
209
- print(f"\n[D1: Greetings] Sourcing real human greetings & cultural openers (Target: {target:,})...")
210
  samples = []
211
-
212
- # Indian Cultural Openers
213
- indian_greetings = [
214
- ("नमस्ते", "नमस्ते! मैं सारस हूँ। आज मैं आपकी क्या सहायता कर सकता हूँ?"),
215
- ("राम राम भाई", "राम राम भाई! सब कुशल मंगल? बताइए, आज किस विषय पर चर्चा करनी है या क्या मदद चाहिए?"),
216
- ("प्रणाम", "सादर प्रणाम! मैं सारस (ViuAI) आपकी सेवा में उपस्थित हूँ। बताइए, आज क्या सीखना या हल करना है?"),
217
- ("सत श्री अकाल", "सत श्री अकाल! मैं सारस हूँ। मैं आपकी किस प्रकार सहायता कर सकता हूँ?"),
218
- ("आदाब", "आदाब! बताइए, आज आपकी क्या खिदमत की जा सकती है?"),
219
- ("Kaise ho bhai?", "Main badhiya hoon bhai! Aap kaise hain? Aaj kis cheez me help chahiye — coding, math ya koi aur sawaal?"),
220
- ("Namaste! How are you today?", "Namaste! I am doing great and ready to assist you. How can I help you today?")
221
  ]
222
- for q, r in indian_greetings:
223
- samples.append({"instruction": q, "response": r, "domain_id": 1})
224
-
225
- # Stream real human greetings & conversational openers from UltraChat (100% Parquet format)
226
- try:
227
- ds_uc = load_dataset("HuggingFaceH4/ultrachat_200k", split="train_sft", streaming=True)
228
- greeting_words = ["hi", "hello", "hey", "morning", "afternoon", "evening", "greetings", "howdy", "welcome"]
229
- for row in ds_uc:
230
- msgs = row.get("messages", [])
231
- if len(msgs) >= 2:
232
- q = clean_text(msgs[0].get("content") or "")
233
- r = clean_text(msgs[1].get("content") or "")
234
- first_few = q[:35].lower()
235
- if any(w in first_few for w in greeting_words) and 10 < len(r) < 300 and not is_duplicate(q):
236
- samples.append({"instruction": q, "response": r, "domain_id": 1})
237
- if len(samples) >= target:
238
- break
239
- except Exception as e:
240
- print(f" ℹ️ UltraChat greeting stream: {e}")
241
-
242
- # Bilingual Hindi Greetings from IITB parallel corpus
243
- if len(samples) < target:
244
  try:
245
- ds_iitb = load_dataset("cfilt/iitb-english-hindi", split="train", streaming=True)
246
- for row in ds_iitb:
247
- t = row.get("translation", {})
248
- hi = clean_text(t.get("hi") or "")
249
- if any(w in hi for w in ["नमस्ते", "प्रणाम", "नमस्कार", "शुभ प्रभात", "धन्यवाद", "स्वागत"]):
250
- if not is_duplicate(hi):
251
- samples.append({"instruction": hi, "response": "नमस्ते! मैं सारस (ViuAI) हूँ। मैं आपकी किस प्रकार सहायता कर सकता हूँ?", "domain_id": 1})
252
- if len(samples) >= target:
253
- break
254
  except Exception as e:
255
- print(f" ℹ️ IITB greeting stream: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
256
 
257
- print(f" ✅ [D1: Greetings] Ingested {len(samples):,} real conversational greeting samples.")
258
  return samples[:target]
259
 
260
 
@@ -556,34 +501,11 @@ def build_domain_multiturn(target=20000):
556
  return samples[:target]
557
 
558
 
559
- # --- Domain 9: Safety & Ethical Refusals ---
560
- def build_domain_safety(target=7000):
561
- print(f"\n[D9: Safety] Sourcing real harmless refusals from Anthropic Harmless (Target: {target:,})...")
562
- samples = []
563
- try:
564
- ds = load_dataset("Anthropic/hh-rlhf", data_dir="harmless-base", split="train", streaming=True)
565
- for row in ds:
566
- chosen = row.get("chosen", "").strip()
567
- if "\n\nAssistant:" in chosen and "\n\nHuman:" in chosen:
568
- parts = chosen.split("\n\nAssistant:")
569
- q = parts[0].replace("\n\nHuman:", "").strip()
570
- ans = parts[1].strip()
571
- if q and ans and not is_duplicate(q):
572
- samples.append({"instruction": clean_text(q), "response": clean_text(ans), "domain_id": 9})
573
- if len(samples) >= target:
574
- break
575
- except Exception as e:
576
- print(f" ℹ️ Anthropic harmless stream: {e}")
577
-
578
- print(f" ✅ [D9: Safety] Ingested {len(samples):,} real ethical refusal samples.")
579
- return samples[:target]
580
-
581
-
582
  # ------------------------------------------------------------------------------
583
  # 4. Master Orchestrator: Ingest, Export Raw, Tokenize & Dual-Upload
584
  # ------------------------------------------------------------------------------
585
  def main():
586
- print("\n🚀 Commencing Master Real-Data Ingestion across all 10 Domains...")
587
  domain_builders = [
588
  (0, build_domain_identity),
589
  (1, build_domain_greetings),
@@ -594,7 +516,6 @@ def main():
594
  (6, build_domain_hindi),
595
  (7, build_domain_summarization_translation),
596
  (8, build_domain_multiturn),
597
- (9, build_domain_safety),
598
  ]
599
 
600
  all_samples = []
@@ -640,22 +561,21 @@ size_categories:
640
 
641
  This is the human-readable, raw multi-task instruction dataset curated for the post-training alignment of foundation model **Sarus** (developed by **ViuAI**).
642
 
643
- ## 📊 Domain Composition (Total: {total_samples:,} Samples)
644
 
645
  | Domain ID | Domain Name | Samples | Sources |
646
  | :---: | :--- | :---: | :--- |
647
- | **D0** | `identity_sarus` | {domain_counts.get('identity_sarus', 0):,} | Real human queries from LMSYS/WildChat grounded to Sarus (ViuAI) |
648
- | **D1** | `greetings_cultural` | {domain_counts.get('greetings_cultural', 0):,} | Real human openers from DailyDialog, EmpatheticDialogues, IITB |
649
- | **D2** | `ncert_indian_history` | {domain_counts.get('ncert_indian_history', 0):,} | ParthKadam2003/NCERT_Dataset + kaifahmad/indian-history-hindi-QA |
650
  | **D3** | `coding_tech` | {domain_counts.get('coding_tech', 0):,} | sahil2801/CodeAlpaca-20k + m-a-p/CodeFeedback-Filtered |
651
  | **D4** | `math_arithmetic` | {domain_counts.get('math_arithmetic', 0):,} | openai/gsm8k + Multi-digit mental arithmetic scratchpad |
652
  | **D5** | `general_stem` | {domain_counts.get('general_stem', 0):,} | tatsu-lab/alpaca (Stanford) |
653
  | **D6** | `hindi_culture` | {domain_counts.get('hindi_culture', 0):,} | iamshnoo/alpaca-cleaned-hindi |
654
  | **D7** | `summarization_translation`| {domain_counts.get('summarization_translation', 0):,} | knkarthick/dialogsum + cfilt/iitb-english-hindi |
655
  | **D8** | `multiturn_dialogue` | {domain_counts.get('multiturn_dialogue', 0):,} | HuggingFaceH4/ultrachat_200k |
656
- | **D9** | `safety_refusal` | {domain_counts.get('safety_refusal', 0):,} | Anthropic/hh-rlhf (harmless-base) |
657
 
658
- 100% real open-source data. Zero synthetic fake data.
659
  """
660
  with open(os.path.join(RAW_EXPORT_DIR, "README.md"), "w", encoding="utf-8") as f:
661
  f.write(readme_content)
 
47
  PAD_TOKEN_ID = 64000
48
  EOT_ID = 64002
49
 
50
+ # 9 Domain Architecture (100% Real Authentic Data, No Safety Domain)
51
  DOMAIN_NAMES = {
52
  0: "identity_sarus",
53
  1: "greetings_cultural",
 
57
  5: "general_stem",
58
  6: "hindi_culture",
59
  7: "summarization_translation",
60
+ 8: "multiturn_dialogue"
 
61
  }
62
 
63
+ # Target Domain Budgets (~253,770 Total High-Purity Real Samples)
64
  DOMAIN_TARGETS = {
65
+ 0: 5061, # Authentic Sarus Identity (ViuAI)
66
+ 1: 8709, # Cultural & Conversational Greetings
67
  2: 40000, # NCERT (Grades 9-12) & Indian History / Constitution
68
  3: 50000, # Coding & Tech (Python, Algorithms, SQL, Web)
69
  4: 30000, # Math & Arithmetic Reasoning (GSM8K + Mental Arithmetic)
70
  5: 35000, # General STEM & World Science (Stanford Alpaca)
71
  6: 35000, # Hindi Language, Culture & Society (Alpaca Hindi)
72
  7: 25000, # Summarization (DialogSum) & Translation (IITB)
73
+ 8: 25000 # Multi-Turn Conversations (UltraChat 200k)
 
74
  }
75
 
76
  print("=" * 85)
77
  print("🌟 ViuAI Sarus-500M — SFT v1 Master Real-Data Builder & Dual-Uploader")
78
+ print(" • Target Capacity: ~253,770 Samples across 9 Capability Domains")
79
  print(" • Model Identity: Sarus (सारस) | Developer: ViuAI")
80
  print(f" • Database 1 (Raw): {RAW_REPO_ID}")
81
  print(f" • Database 2 (NPY): {TOKENIZED_REPO_ID} [sft_v1]")
 
136
  # ------------------------------------------------------------------------------
137
 
138
  # --- Domain 0: Identity (Sarus / ViuAI) ---
139
+ def build_domain_identity(target=5061):
140
+ print(f"\n[D0: Identity] Sourcing authentic Sarus identity dataset (Target: {target:,})...")
141
  samples = []
142
+ json_candidates = [
143
+ os.path.join(BASE_DIR, "data", "sft_identity.json"),
144
+ os.path.join(BASE_DIR, "sft_identity.json")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  ]
146
+ target_path = json_candidates[0]
147
+ if not any(os.path.exists(p) for p in json_candidates):
148
+ try:
149
+ print(f" 📥 Downloading data/sft_identity.json from {MODEL_REPO_ID}...")
150
+ dl = hf_hub_download(repo_id=MODEL_REPO_ID, filename="data/sft_identity.json", token=HF_TOKEN)
151
+ os.makedirs(os.path.dirname(target_path), exist_ok=True)
152
+ shutil.copy(dl, target_path)
153
+ except Exception as e:
154
+ print(f" ℹ️ HF fetch identity warning: {e}")
155
 
156
+ for p in json_candidates:
157
+ if os.path.exists(p):
158
+ with open(p, "r", encoding="utf-8") as f:
159
+ raw = json.load(f)
160
+ for item in raw:
161
+ q = clean_text((item.get("instruction") or "").replace("ViuAi", "ViuAI").replace("Viuai", "ViuAI"))
162
+ r = clean_text((item.get("response") or "").replace("ViuAi", "ViuAI").replace("Viuai", "ViuAI"))
163
+ if q and r and not is_duplicate(q):
164
+ samples.append({"instruction": q, "response": r, "domain_id": 0})
165
+ print(f" ✅ [D0: Identity] Loaded {len(samples):,} authentic Sarus identity samples from {p}.")
166
+ return samples[:target]
167
+
168
+ print(f" ⚠️ Fallback: {len(samples)} identity samples loaded.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  return samples[:target]
170
 
171
 
172
  # --- Domain 1: Greetings & Cultural Openers ---
173
+ def build_domain_greetings(target=8709):
174
+ print(f"\n[D1: Greetings] Sourcing authentic greetings dataset (Target: {target:,})...")
175
  samples = []
176
+ json_candidates = [
177
+ os.path.join(BASE_DIR, "data", "sft_greetings.json"),
178
+ os.path.join(BASE_DIR, "sft_greetings.json")
 
 
 
 
 
 
 
179
  ]
180
+ target_path = json_candidates[0]
181
+ if not any(os.path.exists(p) for p in json_candidates):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  try:
183
+ print(f" 📥 Downloading data/sft_greetings.json from {MODEL_REPO_ID}...")
184
+ dl = hf_hub_download(repo_id=MODEL_REPO_ID, filename="data/sft_greetings.json", token=HF_TOKEN)
185
+ os.makedirs(os.path.dirname(target_path), exist_ok=True)
186
+ shutil.copy(dl, target_path)
 
 
 
 
 
187
  except Exception as e:
188
+ print(f" ℹ️ HF fetch greetings warning: {e}")
189
+
190
+ for p in json_candidates:
191
+ if os.path.exists(p):
192
+ with open(p, "r", encoding="utf-8") as f:
193
+ raw = json.load(f)
194
+ for item in raw:
195
+ q = clean_text((item.get("instruction") or "").replace("ViuAi", "ViuAI").replace("Viuai", "ViuAI"))
196
+ r = clean_text((item.get("response") or "").replace("ViuAi", "ViuAI").replace("Viuai", "ViuAI"))
197
+ if q and r and not is_duplicate(q):
198
+ samples.append({"instruction": q, "response": r, "domain_id": 1})
199
+ print(f" ✅ [D1: Greetings] Loaded {len(samples):,} authentic greeting samples from {p}.")
200
+ return samples[:target]
201
 
202
+ print(f" ⚠️ Fallback: {len(samples)} greeting samples loaded.")
203
  return samples[:target]
204
 
205
 
 
501
  return samples[:target]
502
 
503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
504
  # ------------------------------------------------------------------------------
505
  # 4. Master Orchestrator: Ingest, Export Raw, Tokenize & Dual-Upload
506
  # ------------------------------------------------------------------------------
507
  def main():
508
+ print("\n🚀 Commencing Master Real-Data Ingestion across all 9 Domains...")
509
  domain_builders = [
510
  (0, build_domain_identity),
511
  (1, build_domain_greetings),
 
516
  (6, build_domain_hindi),
517
  (7, build_domain_summarization_translation),
518
  (8, build_domain_multiturn),
 
519
  ]
520
 
521
  all_samples = []
 
561
 
562
  This is the human-readable, raw multi-task instruction dataset curated for the post-training alignment of foundation model **Sarus** (developed by **ViuAI**).
563
 
564
+ ## 📊 Domain Composition (Total: {total_samples:,} Samples across 9 Domains)
565
 
566
  | Domain ID | Domain Name | Samples | Sources |
567
  | :---: | :--- | :---: | :--- |
568
+ | **D0** | `identity_sarus` | {domain_counts.get('identity_sarus', 0):,} | Authentic Sarus & ViuAI ground-truth persona dataset |
569
+ | **D1** | `greetings_cultural` | {domain_counts.get('greetings_cultural', 0):,} | Authentic Indian Cultural (Namaste, Ram Ram) & Developer Openers |
570
+ | **D2** | `ncert_indian_history` | {domain_counts.get('ncert_indian_history', 0):,} | ParthKadam2003/NCERT_Dataset (9-12) + kaifahmad/indian-history-hindi-QA |
571
  | **D3** | `coding_tech` | {domain_counts.get('coding_tech', 0):,} | sahil2801/CodeAlpaca-20k + m-a-p/CodeFeedback-Filtered |
572
  | **D4** | `math_arithmetic` | {domain_counts.get('math_arithmetic', 0):,} | openai/gsm8k + Multi-digit mental arithmetic scratchpad |
573
  | **D5** | `general_stem` | {domain_counts.get('general_stem', 0):,} | tatsu-lab/alpaca (Stanford) |
574
  | **D6** | `hindi_culture` | {domain_counts.get('hindi_culture', 0):,} | iamshnoo/alpaca-cleaned-hindi |
575
  | **D7** | `summarization_translation`| {domain_counts.get('summarization_translation', 0):,} | knkarthick/dialogsum + cfilt/iitb-english-hindi |
576
  | **D8** | `multiturn_dialogue` | {domain_counts.get('multiturn_dialogue', 0):,} | HuggingFaceH4/ultrachat_200k |
 
577
 
578
+ 100% authentic open-source & verified domain data. Zero synthetic fake data. Zero vulgarity.
579
  """
580
  with open(os.path.join(RAW_EXPORT_DIR, "README.md"), "w", encoding="utf-8") as f:
581
  f.write(readme_content)