Coding-With-Bashir commited on
Commit
90807ca
·
verified ·
1 Parent(s): 39e8985

Upload .\scripts\collect_huggingface.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. .//scripts//collect_huggingface.py +79 -0
.//scripts//collect_huggingface.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Standalone Huggingface collector - downloads datasets as JSONL without torch dependency."""
2
+
3
+ import json
4
+ import logging
5
+ from pathlib import Path
6
+
7
+ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
8
+ logger = logging.getLogger(__name__)
9
+
10
+ OUTPUT_DIR = Path("C:/Users/admin/BwengeAi/data/raw/huggingface")
11
+ OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
12
+
13
+ # Key datasets to collect (streaming mode to avoid loading all in memory)
14
+ DATASETS = [
15
+ {"name": "mbazaNLP/kinyarwanda_monolingual_v01.1", "desc": "Monolingual corpus (1.07M rows)"},
16
+ {"name": "CircuitNotion/kinyarwanda_corpus", "desc": "Large corpus (3.52M rows)"},
17
+ {"name": "saillab/alpaca_kinyarwanda_taco", "desc": "Instruction tuning (62k rows)"},
18
+ {"name": "saillab/alpaca-kinyarwanda-cleaned", "desc": "Cleaned instruction (52k rows)"},
19
+ {"name": "mbazaNLP/Kinyarwanda_English_parallel_dataset", "desc": "Parallel corpus (55.7k rows)"},
20
+ {"name": "ChrisToukmaji/kinyarwanda_instruction_tuning", "desc": "Instruction tuning (5k rows)"},
21
+ {"name": "Mikecyane/Kinyarwanda_chat", "desc": "Chat dataset (4.16k rows)"},
22
+ {"name": "RogerB/Kinyarwanda_wikipedia20230920", "desc": "Wikipedia dump (8.05k rows)"},
23
+ {"name": "tianyiwordly/kinyarwanda_denoised", "desc": "Denoised text (783k rows)"},
24
+ {"name": "michsethowusu/Code-170k-kinyarwanda", "desc": "Code in Kinyarwanda (177k rows)"},
25
+ {"name": "FarmerlineML/kinyarwanda_dataset", "desc": "Agriculture Kinyarwanda"},
26
+ {"name": "DigitalUmuganda/kinyarwanda-english-machine-translation-dataset", "desc": "MT dataset (3.38k rows)"},
27
+ ]
28
+
29
+
30
+ def collect_dataset(dataset_config: dict) -> dict:
31
+ from datasets import load_dataset
32
+
33
+ name = dataset_config["name"]
34
+ safe_name = name.replace("/", "_")
35
+ output_path = OUTPUT_DIR / f"{safe_name}.jsonl"
36
+
37
+ logger.info(f"Collecting: {name} ({dataset_config['desc']})")
38
+
39
+ try:
40
+ dataset = load_dataset(name, split="train", streaming=True, trust_remote_code=True)
41
+
42
+ count = 0
43
+ with open(output_path, "w", encoding="utf-8") as f:
44
+ for item in dataset:
45
+ f.write(json.dumps(item, ensure_ascii=False) + "\n")
46
+ count += 1
47
+ if count % 10000 == 0:
48
+ logger.info(f" {count} rows collected...")
49
+
50
+ logger.info(f" Saved {count} rows to {output_path}")
51
+ return {"name": name, "rows": count, "path": str(output_path), "status": "success"}
52
+
53
+ except Exception as e:
54
+ logger.error(f" Failed: {e}")
55
+ return {"name": name, "status": "failed", "error": str(e)}
56
+
57
+
58
+ def main():
59
+ logger.info("=" * 60)
60
+ logger.info("BwengeAi - Huggingface Dataset Collection")
61
+ logger.info("=" * 60)
62
+
63
+ results = []
64
+ for ds_config in DATASETS:
65
+ result = collect_dataset(ds_config)
66
+ results.append(result)
67
+
68
+ summary_path = OUTPUT_DIR / "huggingface_summary.json"
69
+ with open(summary_path, "w", encoding="utf-8") as f:
70
+ json.dump(results, f, indent=2, ensure_ascii=False)
71
+
72
+ successful = sum(1 for r in results if r.get("status") == "success")
73
+ total_rows = sum(r.get("rows", 0) for r in results if r.get("status") == "success")
74
+ logger.info(f"\nDone! {successful}/{len(results)} datasets collected, {total_rows} total rows")
75
+ logger.info(f"Summary: {summary_path}")
76
+
77
+
78
+ if __name__ == "__main__":
79
+ main()