MOH749 commited on
Commit
0191f30
·
verified ·
1 Parent(s): a429112

cleanup: training scripts live in deploy/, not the dataset repo

Browse files
Files changed (1) hide show
  1. build_bocalantics.py +0 -225
build_bocalantics.py DELETED
@@ -1,225 +0,0 @@
1
- # /// script
2
- # dependencies = ["datasets==2.21.0", "huggingface_hub>=0.22", "soundfile", "librosa", "numpy"]
3
- # ///
4
- # NOTE: datasets is pinned to 2.21.0 on purpose — it decodes audio via soundfile.
5
- # datasets >=4.0 requires torchcodec (pulls torch + ffmpeg) just to read the Audio
6
- # column; the pin keeps this a light CPU job.
7
- """Build MOH749/Bocalantics — one unified West African ASR dataset.
8
-
9
- Pulls the clean-licensed source datasets, normalizes them to a single schema,
10
- merges them, and pushes the result to the Hub with a provenance card. Designed
11
- to run on Hugging Face Jobs (HF_TOKEN is injected via job secrets), so the audio
12
- never round-trips through a laptop.
13
-
14
- Run it (after `hf auth login`):
15
- hf jobs uv run --flavor cpu-upgrade --timeout 3h --secrets HF_TOKEN \\
16
- "https://huggingface.co/datasets/MOH749/Bocalantics/resolve/main/build_bocalantics.py"
17
-
18
- Schema (one row): audio(16kHz) · text · lang · source · license · duration.
19
- v1 languages: wo (Wolof), ff (Pulaar/Fula), bam (Bambara). Sereer waits on the
20
- Kallaama re-host (its clean copy is github.com/gauthelo/kallaama-speech-dataset,
21
- not load_dataset-able yet).
22
-
23
- License: the union is CC-BY-SA-4.0 (soynade is share-alike; CC-BY sources
24
- relicense into an SA collection with attribution preserved). Per-row source +
25
- license fields keep the provenance explicit.
26
- """
27
- import collections
28
- import os
29
- import time
30
-
31
- from datasets import (Audio, DatasetDict, Features, Value, concatenate_datasets,
32
- load_dataset)
33
- from huggingface_hub import HfApi
34
-
35
-
36
- def _load_with_retry(hf_id, cfg, tries=8):
37
- """load_dataset with retries — HF shard downloads occasionally drop mid-stream
38
- (RemoteProtocolError / incomplete body); a few retries clear the transient blip."""
39
- last = None
40
- for i in range(tries):
41
- try:
42
- return load_dataset(hf_id, cfg) if cfg else load_dataset(hf_id)
43
- except Exception as exc: # noqa: BLE001 — transient network/download errors
44
- last = exc
45
- print(f" [retry {i + 1}/{tries}] {hf_id} load failed: {type(exc).__name__}: {exc}")
46
- time.sleep(5 * (i + 1))
47
- raise last
48
-
49
- REPO = "MOH749/Bocalantics"
50
- PRIVATE = os.environ.get("BOCALANTICS_PRIVATE", "1") == "1"
51
- SEED = 42
52
-
53
- # (hf_id, config, text_column, lang, license, url, attribution)
54
- # bam-asr-early's transcription lives in the `bam` column (French in `french`).
55
- # Its "bam-asr-all" config already contains jeli-asr + mali-pensé, so we do NOT
56
- # add jeli-asr separately — that would double-count Bambara.
57
- SOURCES = [
58
- ("soynade-research/Wolof-ASR-Data", None, "transcription", "wo", "CC-BY-SA-4.0",
59
- "https://hf.co/datasets/soynade-research/Wolof-ASR-Data", "soynade-research"),
60
- ("ngia/ASR_pulaar", None, "transcription", "ff", "CC-BY-4.0",
61
- "https://hf.co/datasets/ngia/ASR_pulaar", "ngia"),
62
- ("RobotsMali/bam-asr-early", "bam-asr-all", "bam", "bam", "CC-BY-4.0",
63
- "https://hf.co/datasets/RobotsMali/bam-asr-early",
64
- "RobotsMali AI4D Lab (Jeli-ASR, Mali-Pensé / A. Ouattara)"),
65
- ]
66
-
67
- FEATURES = Features({
68
- "audio": Audio(sampling_rate=16000),
69
- "text": Value("string"),
70
- "lang": Value("string"),
71
- "source": Value("string"),
72
- "license": Value("string"),
73
- "duration": Value("float32"),
74
- })
75
-
76
-
77
- def normalize(ds, text_col, lang, source, lic):
78
- """Reduce one source split to the unified schema, keeping the Audio feature."""
79
- has_dur = "duration" in ds.column_names
80
- keep = {"audio"}
81
- remove = [c for c in ds.column_names if c not in keep]
82
-
83
- def _m(ex):
84
- return {
85
- "text": (ex.get(text_col) or "").strip(),
86
- "lang": lang,
87
- "source": source,
88
- "license": lic,
89
- "duration": float(ex["duration"]) if has_dur and ex.get("duration") else 0.0,
90
- }
91
-
92
- ds = ds.map(_m, remove_columns=remove)
93
- ds = ds.filter(lambda ex: bool(ex["text"]))
94
- return ds.cast(FEATURES)
95
-
96
-
97
- def main():
98
- token = os.environ.get("HF_TOKEN")
99
- train_parts, val_parts, test_parts = [], [], []
100
-
101
- for hf_id, cfg, text_col, lang, lic, _url, _attrib in SOURCES:
102
- print(f"[load] {hf_id} (config={cfg}, lang={lang})")
103
- dd = _load_with_retry(hf_id, cfg)
104
- train = normalize(dd["train"], text_col, lang, hf_id, lic)
105
-
106
- if "test" in dd:
107
- test = normalize(dd["test"], text_col, lang, hf_id, lic)
108
- tv = train.train_test_split(test_size=0.1, seed=SEED)
109
- train_parts.append(tv["train"])
110
- val_parts.append(tv["test"])
111
- test_parts.append(test)
112
- else: # single split: carve ~10% val + ~10% test deterministically
113
- a = train.train_test_split(test_size=0.2, seed=SEED)
114
- b = a["test"].train_test_split(test_size=0.5, seed=SEED)
115
- train_parts.append(a["train"])
116
- val_parts.append(b["train"])
117
- test_parts.append(b["test"])
118
- print(f" {hf_id}: +{len(train_parts[-1])} train / +{len(val_parts[-1])} val "
119
- f"/ +{len(test_parts[-1])} test")
120
-
121
- bocal = DatasetDict({
122
- "train": concatenate_datasets(train_parts),
123
- "validation": concatenate_datasets(val_parts),
124
- "test": concatenate_datasets(test_parts),
125
- })
126
-
127
- print("\n[composition]")
128
- for split in ("train", "validation", "test"):
129
- per_lang = collections.Counter(bocal[split]["lang"])
130
- print(f" {split}: {len(bocal[split])} clips {dict(per_lang)}")
131
-
132
- print(f"\n[push] {REPO} (private={PRIVATE})")
133
- bocal.push_to_hub(REPO, private=PRIVATE, token=token)
134
-
135
- _push_card(bocal, token)
136
- print("done.")
137
-
138
-
139
- def _push_card(bocal, token):
140
- rows = "\n".join(
141
- f"| `{hf_id}` | {lang} | {lic} | {attrib} | [link]({url}) |"
142
- for hf_id, _cfg, _tc, lang, lic, url, attrib in SOURCES
143
- )
144
- stats = collections.Counter(bocal["train"]["lang"] + bocal["validation"]["lang"]
145
- + bocal["test"]["lang"])
146
- stat_rows = "\n".join(f"| {k} | {v} |" for k, v in sorted(stats.items()))
147
- card = f"""---
148
- license: cc-by-sa-4.0
149
- language:
150
- - wo
151
- - ff
152
- - bm
153
- task_categories:
154
- - automatic-speech-recognition
155
- pretty_name: Bocalantics
156
- tags:
157
- - west-african
158
- - wolof
159
- - pulaar
160
- - fula
161
- - bambara
162
- - asr
163
- - speech
164
- - low-resource
165
- size_categories:
166
- - 100K<n<1M
167
- ---
168
-
169
- # Bocalantics
170
-
171
- One normalized, license-clean speech corpus for **West African languages** —
172
- Wolof, Pulaar/Fula, and Bambara — merged from the fragmented community datasets
173
- into a single source you can train on anywhere with `load_dataset`.
174
-
175
- West African languages are spoken by one interconnected, multilingual people;
176
- Bocalantics treats them as one corpus so a single model can learn across them.
177
-
178
- ## Schema
179
- | field | type |
180
- |---|---|
181
- | `audio` | Audio (16 kHz) |
182
- | `text` | string — the transcription |
183
- | `lang` | string — `wo` / `ff` / `bam` |
184
- | `source` | string — upstream dataset id |
185
- | `license` | string — upstream license |
186
- | `duration` | float — seconds (0.0 where the source omitted it) |
187
-
188
- Splits: `train` / `validation` / `test`.
189
-
190
- ## Composition (clips)
191
- | lang | clips |
192
- |---|---|
193
- {stat_rows}
194
-
195
- ## Provenance & attribution
196
- Built only from clean-licensed sources, each row carrying its `source` and
197
- `license`. Please credit the upstream creators:
198
-
199
- | source | lang | license | credit | link |
200
- |---|---|---|---|---|
201
- {rows}
202
-
203
- ## License
204
- The collection is released under **CC-BY-SA-4.0** (the share-alike umbrella, since
205
- one source is CC-BY-SA; the CC-BY sources are relicensed into the collection with
206
- attribution preserved). Attribute the upstream creators above.
207
-
208
- ## Load
209
- ```python
210
- from datasets import load_dataset
211
- ds = load_dataset("MOH749/Bocalantics", split="train")
212
- # per-language: ds = ds.filter(lambda x: x["lang"] == "wo")
213
- ```
214
-
215
- ## Roadmap
216
- - v1.1: add **Sereer** + more Wolof/Pulaar via Kallaama (CC-BY-4.0, Jokalante),
217
- once re-hosted from `github.com/gauthelo/kallaama-speech-dataset`.
218
- - Mande siblings (Soninke, Mandinka) await licensed speech data.
219
- """
220
- HfApi().upload_file(path_or_fileobj=card.encode("utf-8"), path_in_repo="README.md",
221
- repo_id=REPO, repo_type="dataset", token=token)
222
-
223
-
224
- if __name__ == "__main__":
225
- main()