yjelassi commited on
Commit
08f5e69
·
verified ·
1 Parent(s): 58e7809

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +157 -0
README.md ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # BA-Lang — Spoken Language Identification checkpoints
2
+
3
+ Checkpoints for **spoken language identification (LID)**: a self-supervised
4
+ speech backbone, pooled with **MHFA**
5
+ (Multi-Head Factorized Attention) and scored with either a standard
6
+ cosine-softmax classifier or **BA-LR** (Binary Attribute Likelihood Ratio),
7
+ a Bernoulli classifier over a learned binary attribute embedding.
8
+
9
+ - Training code / recipe: [https://github.com/AMIAD-Research/BA-Lang]
10
+ - BA-LR / BA-Lang scoring backend: I. Jelassi et al., *"Reconnaissance de la langue parlée explicable avec BA-LR"*, JEP 2026 —
11
+ [isca-archive.org/jep_2026/jelassi26_jep.html](https://www.isca-archive.org/jep_2026/jelassi26_jep.html)
12
+ - BAE (binary auto-encoder): I. Ben-Amor, J.-F. Bonastre, S. Mdhaffar,
13
+ *"Extraction of interpretable and shared speaker-specific speech attributes
14
+ through binary auto-encoder"*, Interspeech 2024.
15
+
16
+ ## Architecture
17
+
18
+ ```
19
+ raw audio (16 kHz)
20
+ │
21
+ ▼
22
+ SSL backbone (MMS-1B or wav2vec2-XLS-R)
23
+ │
24
+ ▼
25
+ Multi-Head Factorized Attentive pooling (MHFA)
26
+ │
27
+ ▼
28
+ classification head
29
+ ├─ cosine-softmax, or
30
+ └─ BA-LR: binary encoder → per-class Bernoulli log-likelihood
31
+ │
32
+ ▼
33
+ language logits
34
+ ```
35
+
36
+
37
+
38
+ ## Checkpoints
39
+
40
+ | File | Backbone | Corpus | Languages | Head | Step | Val. accuracy | Size |
41
+ |---|---|---|---|---|---|---|---|
42
+ | `MMS-Fleurs-step-010360-val_classif_acc-0.9168118238449097.ckpt` | MMS-1B | FLEURS | 102 | cosine-softmax | 10360 | 91.68% | 3.86 GB |
43
+ | `MMS-Fleurs-e2e-balang-stepstep-008856-val_classif_acc-0.9167537689208984.ckpt` | MMS-1B | FLEURS | 102 | BA-Lang (e2e) | 8856 | 91.68% | 3.87 GB |
44
+ | `MMS-Fleurs-e2e-balang-MIR-rho-0.95-step-032472-val_classif_acc-0.90935212373733...ckpt` | MMS-1B | FLEURS | 102 | BA-Lang (e2e) + Matryoshka-inspired dropout, ρ=0.95 | 32472 | 90.94% | 3.87 GB |
45
+ | `MMS-Fleurs-e2e-balang-ND-rho-0.857-step-047232-val_classif_acc-0.89306861162185...ckpt` | MMS-1B | FLEURS | 102 | BA-Lang (e2e) + Nested Dropout, ρ=0.857 | 47232 | 89.31% | 3.87 GB |
46
+ | `MMS-Tidylang-step-008533-val_classif_acc-0.9778640866279602.ckpt` | MMS-1B | Tidylang | 35 | cosine-softmax | 8533 | 97.79% | 3.86 GB |
47
+ | `MMS-Tidylang-e2e-balang-step-005565-val_classif_acc-0.9929152131080627.ckpt` | MMS-1B | Tidylang | 35 | BA-Lang (e2e) | 5565 | 99.29% | 3.87 GB |
48
+ | `XLSR-Fleurs-step-005904-val_classif_acc-0.8094159960746765.ckpt` | wav2vec2-XLS-R | FLEURS | 102 | cosine-softmax | 5904 | 80.94% | 1.27 GB |
49
+ | `XLSR-Fleurs-e2e-balang-step-047232-val_classif_acc-0.8120864033699036.ckpt` | wav2vec2-XLS-R | FLEURS | 102 | BA-Lang (e2e) | 47232 | 81.21% | 1.27 GB |
50
+ | `XLSR-Tidylang-step-008904-val_classif_acc-0.9662737846374512.ckpt` | wav2vec2-XLS-R | Tidylang | 35 | cosine-softmax | 8904 | 96.63% | 1.27 GB |
51
+ | `XLSR-Tidylang-e2e-balang-step-032648-val_classif_acc-0.9860262870788574...ckpt` | wav2vec2-XLS-R | Tidylang | 35 | BA-Lang (e2e) | 32648 | 98.60% | 1.27 GB |
52
+
53
+
54
+
55
+ ## Datasets
56
+
57
+ Training is done separately on two corpora — pick the checkpoint matching
58
+ the languages you need.
59
+
60
+ - **[FLEURS](https://huggingface.co/datasets/google/fleurs)** (102
61
+ languages, ISO 639-3): `afr, amh, ara, asm, ast, aze, bel, ben, bos, bul,
62
+ cat, ceb, ces, ckb, cmn, cym, dan, deu, ell, eng, est, fas, fil, fin, fra,
63
+ ful, gle, glg, guj, hau, heb, hin, hrv, hun, hye, ibo, ind, isl, ita, jav,
64
+ jpn, kam, kan, kat, kaz, kea, khm, kir, kor, lao, lav, lin, lit, ltz, lug,
65
+ luo, mal, mar, mkd, mlt, mon, mri, msa, mya, nep, nld, nob, nso, nya, oci,
66
+ ori, orm, pan, pol, por, pus, ron, rus, slk, slv, sna, snd, som, spa, srp,
67
+ swa, swe, tam, tel, tgk, tha, tur, ukr, umb, urd, uzb, vie, wol, xho, yor,
68
+ yue, zul`.
69
+ - **Tidylang** (35 languages): `TidyVoiceX_ASV` (train/dev) and
70
+ `TidyVoiceX2_ASV` (eval), from Mozilla Data Collective
71
+ ([train/dev](https://mozilladatacollective.com/datasets/cmihtsewu023so207xot1iqqw),
72
+ [eval](https://mozilladatacollective.com/datasets/cmkv32i5e02tumg07j79d3c35)):
73
+ `ara, bak, bel, ben, bul, cat, chv, cym, deu, div, ell, eng, fas, fra, hin,
74
+ hye, jpn, kat, lit, lug, mal, mar, nld, ori, pol, por, rus, tam, tha, tuk,
75
+ tur, uig, uzb, yue, zho`.
76
+
77
+
78
+
79
+ ```python
80
+ import yaml
81
+ lang_list = yaml.safe_load(open("configs/data/fleurs.yaml"))["language_list"]
82
+ # or configs/data/tidylang.yaml for the Tidylang checkpoints
83
+ ```
84
+
85
+ ## Quickstart — inference on your own audio
86
+
87
+ ```bash
88
+ git clone https://github.com/AMIAD-Research/BA-Lang
89
+ cd BA-Lang
90
+ python -m venv .venv && source .venv/bin/activate
91
+ pip install -e ".[dev]"
92
+
93
+ pip install huggingface_hub
94
+ python -c "
95
+ from huggingface_hub import hf_hub_download
96
+ hf_hub_download(
97
+ repo_id='yjelassi/BA-Lang',
98
+ filename='MMS-Fleurs-e2e-balang-stepstep-008856-val_classif_acc-0.9167537689208984.ckpt',
99
+ local_dir='.',
100
+ )
101
+ "
102
+ ```
103
+
104
+ Then, on a single audio file (no manifest needed — this loads the
105
+ checkpoint directly and runs one forward pass):
106
+
107
+ ```python
108
+ import torch
109
+ import torchaudio
110
+ import yaml
111
+
112
+ from balr_lid.models.lid_model import LanguageIdentificationModel
113
+
114
+ CHECKPOINT = "MMS-Fleurs-e2e-balang-stepstep-008856-val_classif_acc-0.9167537689208984.ckpt"
115
+ LANGUAGES = yaml.safe_load(open("configs/data/fleurs.yaml"))["language_list"]
116
+
117
+ model = LanguageIdentificationModel.load_from_checkpoint(
118
+ CHECKPOINT, map_location="cpu", weights_only=False
119
+ )
120
+ model.eval()
121
+
122
+ waveform, sr = torchaudio.load("my_audio.wav")
123
+ if waveform.shape[0] > 1:
124
+ waveform = waveform.mean(dim=0, keepdim=True)
125
+ if sr != 16000:
126
+ waveform = torchaudio.functional.resample(waveform, sr, 16000)
127
+
128
+ with torch.no_grad():
129
+ out = model(waveform)
130
+ probs = out["logits"].softmax(dim=-1)[0]
131
+
132
+ top5 = probs.topk(5)
133
+ for score, idx in zip(top5.values, top5.indices):
134
+ print(f"{LANGUAGES[idx]}: {score.item():.3f}")
135
+ ```
136
+
137
+
138
+
139
+ ### Batch inference over a dataset
140
+
141
+ To evaluate on many files at once (accuracy, confusion matrix, embedding
142
+ dump), build a manifest CSV (see
143
+ [docs/data_manifest.md](https://github.com/AMIAD-Research/BA-Lang))
144
+ and use the repo's batch script instead:
145
+
146
+ ```bash
147
+ python -m balr_lid.inference \
148
+ --checkpoint MMS-Fleurs-e2e-balang-stepstep-008856-val_classif_acc-0.9167537689208984.ckpt \
149
+ --manifest data/manifests/fleurs-test.csv \
150
+ --audio-root /path/to/fleurs/audio \
151
+ --language-list afr amh ara ... \
152
+ --output predictions.csv
153
+ ```
154
+
155
+ `--language-list` must match the checkpoint's training corpus, in order
156
+ (see [Datasets](#datasets) above).
157
+