|
| 1 | +# interscript/ml-models |
| 2 | + |
| 3 | +Unified training framework for Interscript ML-powered maps. |
| 4 | + |
| 5 | +**Status:** skeleton (P0 in TODO.rababa/10). Framework abstractions |
| 6 | +implemented and tested. Task data modules + configs ready; full |
| 7 | +training requires GPU + dataset fetch. |
| 8 | + |
| 9 | +## What this is |
| 10 | + |
| 11 | +One training repo for every ML map in Interscript: |
| 12 | + |
| 13 | +- **rababa_arabic** — Arabic diacritization (adds harakat) |
| 14 | +- **rababa_hebrew** — Hebrew diacritization (adds nikud) |
| 15 | +- **secryst_thai_ipa** — Thai → IPA transliteration |
| 16 | + |
| 17 | +Each task is a **config + data module**. The training framework is |
| 18 | +shared. Adding a new transliteration pair (Khmer → IPA, Japanese → |
| 19 | +Romaji) is one new directory under `src/tasks/` — zero edits to |
| 20 | +framework code. |
| 21 | + |
| 22 | +## Architecture |
| 23 | + |
| 24 | +``` |
| 25 | +src/ |
| 26 | +├── framework/ # SHARED abstractions (MECE) |
| 27 | +│ ├── config.py # TaskConfig loaded from YAML |
| 28 | +│ ├── registry.py # Plugin registry (OCP) |
| 29 | +│ ├── data.py # DataModule ABC |
| 30 | +│ ├── model.py # ModelModule ABC (teacher + student) |
| 31 | +│ ├── trainer.py # BaseTrainer + FineTune + Distill (DRY) |
| 32 | +│ ├── evaluator.py # BaseEvaluator + edit_distance + DER/PER utils |
| 33 | +│ ├── exporter.py # OnnxExporter ABC |
| 34 | +│ └── pipeline.py # TrainingPipeline orchestrator |
| 35 | +├── tasks/ |
| 36 | +│ ├── rababa_arabic/ # config.yaml + data.py + student.py + metrics.py |
| 37 | +│ ├── rababa_hebrew/ |
| 38 | +│ └── secryst_thai_ipa/ |
| 39 | +└── cli.py # python -m src.cli train --task rababa_arabic |
| 40 | +``` |
| 41 | + |
| 42 | +## Design principles (project conventions) |
| 43 | + |
| 44 | +- **OCP** — adding a task = one new directory. Adding a metric, model |
| 45 | + architecture, or data source = one new subclass + `@register_*` |
| 46 | + decorator. Framework code is never edited. |
| 47 | +- **MECE** — each module owns one concern. Data has no knowledge of |
| 48 | + model architecture. Model has no knowledge of trainer. Trainer has |
| 49 | + no knowledge of evaluator. |
| 50 | +- **DRY** — the epoch loop, edit-distance math, and ONNX export |
| 51 | + wrapper are written once. |
| 52 | +- **Model-driven, semantically-driven** — class names mirror domain |
| 53 | + concepts (`RababaArabicData`, `DEREvaluator`, `SecrystThaiIpaStudent`). |
| 54 | +- **Performance** — frozen dataclasses for config; lazy imports for |
| 55 | + torch so framework tests run without GPU deps. |
| 56 | + |
| 57 | +## Quick start |
| 58 | + |
| 59 | +```bash |
| 60 | +scripts/setup_env.sh # creates .venv, installs deps |
| 61 | +scripts/fetch_data.sh # fetch raw datasets (set env vars first) |
| 62 | +scripts/train.sh rababa_arabic # full training pipeline |
| 63 | +scripts/export.sh rababa_arabic # export student to ONNX |
| 64 | +scripts/publish.sh rababa_arabic # upload to HuggingFace Hub |
| 65 | +``` |
| 66 | + |
| 67 | +Or via the CLI directly: |
| 68 | + |
| 69 | +```bash |
| 70 | +python -m src.cli list |
| 71 | +python -m src.cli train --task rababa_arabic --data-root data --out-root models |
| 72 | +python -m src.cli evaluate --task secryst_thai_ipa |
| 73 | +python -m src.cli export --task rababa_hebrew |
| 74 | +``` |
| 75 | + |
| 76 | +## Adding a new task |
| 77 | + |
| 78 | +1. Create `src/tasks/<name>/config.yaml` (copy from an existing task). |
| 79 | +2. Create `src/tasks/<name>/data.py` extending `DataModule`, decorated |
| 80 | + with `@register_data_module("<name>_data")`. |
| 81 | +3. Create `src/tasks/<name>/student.py` extending `ModelModule`, |
| 82 | + decorated with `@register_model_module("<name>_student")`. |
| 83 | +4. Create `src/tasks/<name>/metrics.py` extending `BaseEvaluator`, |
| 84 | + decorated with `@register_evaluator("<metric>")`. |
| 85 | +5. Run `python -m src.cli train --task <name>`. |
| 86 | + |
| 87 | +That's it. No framework edits. |
| 88 | + |
| 89 | +## Tests |
| 90 | + |
| 91 | +```bash |
| 92 | +pytest -v |
| 93 | +``` |
| 94 | + |
| 95 | +Framework tests run without torch (CPU-only, fast). Training and ONNX |
| 96 | +export tests are gated behind `@pytest.mark.gpu` and require the |
| 97 | +`[train]` and `[export]` extras. |
| 98 | + |
| 99 | +## License |
| 100 | + |
| 101 | +MIT. Model weights are released under their own licenses (see |
| 102 | +`docs/model_card.md` per task). |
0 commit comments