Download build.py from pankajpandey-dev/hindi-instruct-mixed-6k-recipe: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/datasets/pankajpandey-dev/hindi-instruct-mixed-6k-recipe/resolve/main/build.py
- Command line
-
hf download hf://datasets/pankajpandey-dev/hindi-instruct-mixed-6k-recipe/build.py
-
curl -L -o build.py https://huggingface.co/datasets/pankajpandey-dev/hindi-instruct-mixed-6k-recipe/resolve/main/build.py
1.3 kB
| """Rebuild the 6k Hindi instruction mix from AI4Bharat source. | |
| Run: python build.py (needs `pip install datasets`)""" | |
| from datasets import load_dataset, concatenate_datasets | |
| import random; random.seed(3407) | |
| CHRF_MIN, PER_SOURCE = 50.0, 3000 | |
| anudesh = load_dataset("ai4bharat/indic-instruct-data-v0.1", "anudesh", split="hi") | |
| dolly = load_dataset("ai4bharat/indic-instruct-data-v0.1", "dolly", split="hi") | |
| anudesh_c = anudesh.map(lambda ex: {"conversations": | |
| [{"role": m["role"], "content": m["content"]} for m in ex["messages"]]}, | |
| remove_columns=anudesh.column_names) | |
| dolly_f = dolly.filter(lambda ex: (ex.get("quality_metrics") or {}).get("chrF", 0) >= CHRF_MIN) | |
| def d2c(ex): | |
| u = ex["instruction"].strip() + (("\n\n"+ex["context"].strip()) if ex.get("context") else "") | |
| return {"conversations": [{"role":"user","content":u}, | |
| {"role":"assistant","content":ex["response"].strip()}]} | |
| dolly_c = dolly_f.map(d2c, remove_columns=dolly_f.column_names) | |
| def take(ds,n): | |
| i=list(range(len(ds))); random.shuffle(i); return ds.select(i[:min(n,len(ds))]) | |
| mixed = concatenate_datasets([take(anudesh_c,PER_SOURCE), take(dolly_c,PER_SOURCE)]).shuffle(seed=3407) | |
| print("final:", len(mixed)); mixed.to_json("hindi_instruct_mixed_6k.jsonl", force_ascii=False) | |