Download tools/make_tiny_corpus.py from RANITBAG/on_the_way: direct link, hf CLI and curl.
- Browser
- Download file 2.97 kB
-
https://huggingface.co/RANITBAG/on_the_way/resolve/main/tools/make_tiny_corpus.py
- Command line
-
hf download hf://RANITBAG/on_the_way/tools/make_tiny_corpus.py
-
curl -L -o make_tiny_corpus.py https://huggingface.co/RANITBAG/on_the_way/resolve/main/tools/make_tiny_corpus.py
2.97 kB
| #!/usr/bin/env python3 | |
| """make_tiny_corpus.py -- deterministic synthetic multilingual corpus for | |
| pipeline smoke tests (NOT real training data; documents are templated). | |
| Writes training_data/tiny/{lang}.txt (one document per line) and | |
| training_data/tiny/manifest.json in the training data-manifest schema. | |
| """ | |
| from __future__ import annotations | |
| import json | |
| import random | |
| from pathlib import Path | |
| LINES = { | |
| "en": ["The government announced new measures for the economy today.", | |
| "Scientists published a study on renewable energy sources."], | |
| "hi": ["सरकार ने आज अर्थव्यवस्था के लिए नए उपायों की घोषणा की।", | |
| "वैज्ञानिकों ने नवीकरणीय ऊर्जा पर एक अध्ययन प्रकाशित किया।"], | |
| "zh": ["政府今天公布了经济新措施。", "科学家发表了一项关于可再生能源的研究。"], | |
| "ar": ["أعلنت الحكومة إجراءات جديدة للاقتصاد اليوم.", | |
| "نشر العلماء دراسة حول مصادر الطاقة المتجددة."], | |
| "ru": ["Правительство сегодня объявило новые меры для экономики.", | |
| "Ученые опубликовали исследование по возобновляемой энергии."], | |
| "ta": ["அரசு இன்று பொருளாதாரத்திற்கான புதிய நடவடிக்கைகளை அறிவித்தது.", | |
| "அறிவியலாளர்கள் புதுப்பிக்கத்தக்க ஆற்றல் குறித்த ஆய்வை வெளியிட்டனர்."], | |
| } | |
| def main() -> int: | |
| out = Path("training_data/tiny") | |
| out.mkdir(parents=True, exist_ok=True) | |
| rng = random.Random(0) | |
| datasets = [] | |
| for lang, seeds in sorted(LINES.items()): | |
| lines = [s + f" [doc {i}]" for i in range(40) for s in seeds] | |
| rng.shuffle(lines) | |
| path = out / f"{lang}.txt" | |
| path.write_text("\n".join(lines) + "\n", encoding="utf-8") | |
| datasets.append({"dataset_id": f"tiny-{lang}", "language": lang, | |
| "script": {"en": "Latn", "hi": "Deva", "zh": "Hani", | |
| "ar": "Arab", "ru": "Cyrl", "ta": "Taml"}[lang], | |
| "license": "CC0-1.0 (synthetic)", "provenance": | |
| "templated synthetic smoke-test corpus; not real data", | |
| "path": str(path)}) | |
| (out / "manifest.json").write_text(json.dumps( | |
| {"schema_version": 1, "datasets": datasets}, indent=2, ensure_ascii=False) + "\n", | |
| encoding="utf-8") | |
| print(f"tiny corpus -> {out} ({len(datasets)} languages, 80 docs each)") | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |