pankajpandey-dev commited on
Commit
ad75260
·
verified ·
1 Parent(s): 6a446c9

Upload build.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. build.py +24 -0
build.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Rebuild the 6k Hindi instruction mix from AI4Bharat source.
2
+ Run: python build.py (needs `pip install datasets`)"""
3
+ from datasets import load_dataset, concatenate_datasets
4
+ import random; random.seed(3407)
5
+
6
+ CHRF_MIN, PER_SOURCE = 50.0, 3000
7
+ anudesh = load_dataset("ai4bharat/indic-instruct-data-v0.1", "anudesh", split="hi")
8
+ dolly = load_dataset("ai4bharat/indic-instruct-data-v0.1", "dolly", split="hi")
9
+
10
+ anudesh_c = anudesh.map(lambda ex: {"conversations":
11
+ [{"role": m["role"], "content": m["content"]} for m in ex["messages"]]},
12
+ remove_columns=anudesh.column_names)
13
+
14
+ dolly_f = dolly.filter(lambda ex: (ex.get("quality_metrics") or {}).get("chrF", 0) >= CHRF_MIN)
15
+ def d2c(ex):
16
+ u = ex["instruction"].strip() + (("\n\n"+ex["context"].strip()) if ex.get("context") else "")
17
+ return {"conversations": [{"role":"user","content":u},
18
+ {"role":"assistant","content":ex["response"].strip()}]}
19
+ dolly_c = dolly_f.map(d2c, remove_columns=dolly_f.column_names)
20
+
21
+ def take(ds,n):
22
+ i=list(range(len(ds))); random.shuffle(i); return ds.select(i[:min(n,len(ds))])
23
+ mixed = concatenate_datasets([take(anudesh_c,PER_SOURCE), take(dolly_c,PER_SOURCE)]).shuffle(seed=3407)
24
+ print("final:", len(mixed)); mixed.to_json("hindi_instruct_mixed_6k.jsonl", force_ascii=False)