muruganmath commited on
Commit
976708c
Β·
verified Β·
1 Parent(s): 09e1608

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +283 -0
README.md CHANGED
@@ -1,3 +1,286 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
 
1
+ # Model card: whisper-large-v3 + LoRA "main" (machine-sound adapter) and voice agent
2
+
3
+ | | |
4
+ |---|---|
5
+ | **Model** | `whisper_ft/out/whisper-lora/main/adapter`: LoRA adapter for `openai/whisper-large-v3` |
6
+ | **Base** | `openai/whisper-large-v3`, commit `06f233fe06e710322aca913c1bc4249a0d71fce1`, Apache-2.0, local hash-locked copy `models/whisper-large-v3` |
7
+ | **Trained** | 2026-11-08 18:44 β†’ 2026-11-09 03:40 UTC (8 h 56 min, one RTX 5070 12 GB) |
8
+ | **Task** | (1) Speech β†’ text (inherited from the base). (2) Machine sound β†’ templated text description (what the adapter learned) |
9
+ | **Voice I/O** | `voice_agent/`: audio in (ACS phone stream, browser mic or file) β†’ this model β†’ reply text β†’ local TTS (`facebook/mms-tts-eng`) β†’ audio out |
10
+ | **Licence** | **Non-commercial only.** Training data includes CC-BY-NC-4.0 data, and the TTS voice is CC-BY-NC-4.0 (see [Licences](#licences)) |
11
+ | **Status** | Research prototype. Not validated on real factory audio or real operators |
12
+
13
+ ---
14
+
15
+ ## 1. What the model does
16
+
17
+ The adapter was trained to **describe machine sounds**, not to transcribe speech. None of its training
18
+ data contains speech. For a 10 s clip it emits one templated line:
19
+
20
+ | Source data | Output template | Example |
21
+ |---|---|---|
22
+ | Machine anomaly | `machine: …; condition: …; status: …; fault: …; noise: …` | `machine: fan; condition: high load; status: anomalous; fault: overheating; noise: low noise` |
23
+ | Engine | `engine sound; rpm mean M range A to B; torque mean T nm` | `engine sound; rpm mean 2870 range 1350 to 5020; torque mean 356 nm` |
24
+
25
+ Label vocabulary (training split):
26
+ - **machine:** pump, electric motor, compressor, valve, fan, conveyor belt
27
+ - **condition:** idle, normal load, high load
28
+ - **status:** normal, anomalous
29
+ - **fault:** none, bearing fault, overheating, imbalance, obstruction, cavitation
30
+ - **noise:** clean, low noise, medium noise, high noise
31
+
32
+ The model has **not lost its speech ability**. On speech it still transcribes English as well as the stock
33
+ base model (see Β§5.2). The voice agent uses both behaviours:
34
+ - **Speech** β†’ transcript β†’ spoken read-back ("I heard: …").
35
+ - **Machine sound** β†’ re-decoded in template mode β†’ spoken diagnosis ("Sound check. This is a fan under
36
+ high load. It sounds abnormal. Possible fault: overheating.").
37
+
38
+ ### Intended use
39
+ - Research and prototyping: voice interaction for manufacturing staff, and acoustic machine-condition
40
+ screening, both **with a human in the loop**.
41
+ - Offline evaluation of how a Whisper LoRA adapter behaves on non-speech audio.
42
+
43
+ ### Out of scope / do not use for
44
+ - **Maintenance or safety decisions** without human verification. The diagnosis is a model estimate
45
+ trained on synthetic sounds (Β§7).
46
+ - Reading back **alarm codes or part numbers** where an error matters (Β§5.4).
47
+ - Commercial use (Β§9).
48
+ - Languages other than English. Decoding is forced to `en`.
49
+
50
+ ---
51
+
52
+ ## 2. System overview (voice input β†’ voice output)
53
+
54
+ ```
55
+ caller / operator audio
56
+ β”œβ”€ ACS phone call: media WebSocket /acs/ws (PCM16 16 kHz JSON frames)
57
+ β”œβ”€ browser mic: http://localhost:8000 (/web/ws live, or "Record a message" β†’ POST /recordings)
58
+ └─ file: speak_transcript.py, scripts/e2e_voice_check.py --file
59
+ β”‚
60
+ β–Ό
61
+ utterance segmentation: live = streaming energy VAD (adaptive noise floor)
62
+ files = mfg_whisper energy VAD (configs/default.yaml audio.vad)
63
+ β”‚
64
+ β–Ό
65
+ Whisper large-v3 + main adapter, speech decoding: ontology prompt, default suppress_tokens,
66
+ confidence flags, ontology normalizer
67
+ β”‚
68
+ β”œβ”€ speech ───────────▢ noise / hallucination guard ──▢ "I heard: <transcript>"
69
+ β”‚
70
+ └─ not speech ───────▢ same model, template decoding (no prompt, suppress_tokens=[], greedy,
71
+ peak βˆ’1 dBFS) ──▢ parse template ──▢ "Sound check. This is …"
72
+ (an incomplete or inconsistent template is never spoken)
73
+ β”‚
74
+ β–Ό
75
+ text β†’ speakable form (digits β†’ words, codes spelled: "F007" β†’ "eff zero zero seven")
76
+ β”‚
77
+ β–Ό
78
+ MMS-TTS (VITS, 16 kHz, local) β†’ PCM16 β†’ ACS AudioData frames / browser playback / reply WAV
79
+ caller speech during playback β†’ StopAudio (barge-in)
80
+ ```
81
+
82
+ All recognition and synthesis runs locally on one GPU. ACS is only the telephony transport. No Azure AI
83
+ or Speech service is used.
84
+
85
+ ---
86
+
87
+ ## 3. Training data
88
+
89
+ | Dataset | Hugging Face id | Nature | Licence | Train | Val | Test |
90
+ |---|---|---|---|---|---|---|
91
+ | anomaly | `mandipgoswami/AnomalyMachine-50K` | **Fully synthetic** (signal-processing synthesis), 10 s clips | CC-BY-4.0 | 20,000 | 7,500 | 7,499 |
92
+ | engine | `huggingbear12/procedural-engine-sounds` | **Procedurally generated**, noise-free, 4.1–12.3 s clips | **CC-BY-NC-4.0** | 4,497 | 717 | 717 |
93
+ | ego | `VerboseTechLabs/manufacturing-unit-egocentric-sample` | Real egocentric factory video | CC-BY-4.0 | **not used** | β€” | β€” |
94
+
95
+ - **Volume:** 70.0 h train, 23.1 h val, 23.1 h test.
96
+ - **Anomaly train balance:** 10,000 normal and 10,000 anomalous; faults about 2,000 each; the four noise
97
+ levels about 5,000 each; machine types 2,795–3,588 each.
98
+ - **No real factory recordings and no speech.**
99
+ - **Preprocessing:** mono β†’ 16 kHz β†’ ≀ 30 s chunks; silent or short chunks rejected; peak-normalised to
100
+ βˆ’1 dBFS (`whisper_ft/scripts/preprocess.py`).
101
+ - **Manifest hashes:** recorded in `adapter/lineage.json` (train `793e4128…`, val `44c8ad4b…`,
102
+ test `e5510f27…`).
103
+
104
+ ---
105
+
106
+ ## 4. Training procedure
107
+
108
+ | | |
109
+ |---|---|
110
+ | Method | LoRA (PEFT) on a frozen **8-bit** base (`BitsAndBytesConfig(load_in_8bit=True)`, `prepare_model_for_kbit_training`) |
111
+ | LoRA | r 32, alpha 64, dropout 0.05; `q/k/v/out_proj`, `fc1`, `fc2` in encoder **and** decoder (57.7 M trainable parameters) |
112
+ | Optimisation | AdamW 8-bit, lr 1e-4, 5 % warmup, cosine; batch 4 Γ— grad-accum 8 (effective 32); 3 epochs = 2,298 steps; bf16; gradient checkpointing |
113
+ | Selection | Best checkpoint by WER on a fixed, stratified 600-clip validation subset (eval every 500 steps): `checkpoint-2298` |
114
+ | Loss | 4.52 at the start β†’ 0.091 at the end (train); validation loss 0.276 |
115
+ | Compute | 13.26 s/optimizer step; peak 10.36 GB VRAM reserved; 31,900 s wall time |
116
+ | Software | torch 2.15.0, transformers 5.22.2, peft 0.21.2, bitsandbytes 0.50.2, accelerate 1.15.0, Python 3.11.18 |
117
+
118
+ Fixes applied in training (see `whisper_ft/README.md`):
119
+ - `model_accepts_loss_kwargs = False`, so the loss is correctly scaled by 1/accumulation.
120
+ - `suppress_tokens=[]` for the fine-tuned model, because large-v3's default list blocks `:` and `;`,
121
+ which every template needs.
122
+
123
+ ---
124
+
125
+ ## 5. Evaluation
126
+
127
+ ### 5.1 Machine-sound descriptions (what the adapter was trained for)
128
+
129
+ Validation subset (600 clips, stratified), end of training:
130
+
131
+ | Metric | Value |
132
+ |---|---|
133
+ | WER (whole template) | 0.185 (anomaly 0.089, engine 0.272) |
134
+ | CER | 0.080 |
135
+ | Exact template match | 0.222 |
136
+ | Mean per-field exact match | 0.596 |
137
+ | Binary anomaly F1 (`status`) | **1.00** |
138
+
139
+ Gaps:
140
+ - **Not yet evaluated on the test split.** The only test-set runs in `out/eval/` are `fake_*` smoke tests.
141
+ Run `whisper_ft/scripts/evaluate.py --manifest manifests/test.jsonl --adapter out/whisper-lora/main/adapter`.
142
+ - **Per-field and engine-tolerance numbers are not yet reported** (RPM within Β±50, torque within Β±5 Nm).
143
+ - **Anomaly F1 of 1.00 is on synthetic data.** Expect much lower on real machines.
144
+ - **Spot checks (2026-11-12):**
145
+ - Test clip `fan_high_load_normal_none_6612`: fully correct.
146
+ - **Training** clip `505_Engine-C`: predicted RPM mean 4660 (range 3870–5200); the label is 2870
147
+ (range 1350–5020). The torque came out garbled (`6-7-0-8`). **Engine numbers are unreliable even
148
+ on training data.**
149
+
150
+ ### 5.2 Speech recognition (inherited ability)
151
+
152
+ Five operator sentences synthesised with espeak-ng, clean and mixed with engine noise at 10 dB SNR:
153
+
154
+ | Path | WER clean | WER noisy |
155
+ |---|---|---|
156
+ | Stock large-v3 (voice-agent decoding) | 0.20 | 0.20 |
157
+ | Main adapter, voice-agent decoding | 0.20 | 0.20 |
158
+ | Main adapter, its own template decoding | 0.18 | 0.18 |
159
+
160
+ - All remaining errors are number formatting only ("F zero zero seven" β†’ "F007",
161
+ "four hundred and fifty" β†’ "450"). Every word was recognised.
162
+ - **Synthetic speech only.** No WER has been measured on real human voices, accents, or real factory
163
+ noise. One live browser session by the developer produced a normal turn; its transcript is not logged
164
+ by design.
165
+
166
+ ### 5.3 Voice agent end to end
167
+
168
+ | Check | Result |
169
+ |---|---|
170
+ | Live simulated call: 38.7 s, 5 sentences, continuous engine noise, real time over ACS | 5/5 utterances correct; no false turns in machine-only gaps; reply ready 230–900 ms after the speaker stops (first turn about 1 s) |
171
+ | Recording upload (`POST /recordings`) | Round trip 0.3–1.1 s for 6–10 s messages |
172
+ | Noise and silence only (engine, anomaly clips, digital silence) | Never spoken as speech. Hallucinations seen and blocked: "Thank you for watching!", "so", "you", "." and the fake alarm code **"E08"** (from the domain prompt) |
173
+ | Spoken diagnosis, uploaded machine clips | Spoken whenever the template parses (e.g. clips 0016 and 0021 β†’ "fan, high load, abnormal, possible overheating"; these clips are unlabelled) |
174
+ | Unit and integration tests | 194 passed (`tests/`) |
175
+
176
+ ### 5.4 Voice output (TTS) intelligibility
177
+
178
+ Checked by synthesising a reply with MMS-TTS and transcribing it back with Whisper:
179
+
180
+ | Spoken text | Heard back |
181
+ |---|---|
182
+ | "Sound check. This is a fan under high load. It sounds abnormal. Possible fault: overheating." | Identical |
183
+ | "I heard: Alarm F007 on line 3, …" | "alarm F017", "alarm F", "F-Zero-Zero said" (varies) |
184
+ | "… shows fault E42" | "faulty for 2" |
185
+ | The word "engine" | "Insan", "Ed Sheik", "Indian" (so replies say "motor") |
186
+ | "idling" | "piling" (so replies say "at idle") |
187
+
188
+ **Spoken alarm codes and part numbers are not reliable.** MMS-TTS has no punctuation in its vocabulary,
189
+ so there are no pauses between code characters.
190
+
191
+ ---
192
+
193
+ ## 6. How to run inference
194
+
195
+ Conda env `mfg_whisper`; run from `finetune_whisper/`.
196
+
197
+ ```bash
198
+ # Machine-sound description only (template text)
199
+ cd whisper_ft && python scripts/infer.py ../recording/clip.wav --json && cd ..
200
+
201
+ # File β†’ transcript or diagnosis β†’ spoken reply WAV (loads the models itself)
202
+ python speak_transcript.py recording/clip.wav --show # β†’ out/speak/clip_reply.wav
203
+
204
+ # Live server: ACS media WebSocket, browser mic page, recordings API
205
+ python scripts/run_voice_agent.py --adapter whisper_ft/out/whisper-lora/main/adapter
206
+ python scripts/e2e_voice_check.py --file recording/clip.wav # β†’ recording/<name>{,_reply}.wav, <name>.json
207
+ python scripts/e2e_voice_check.py # microphone (needs sounddevice)
208
+ ```
209
+
210
+ **Decoding settings that matter:**
211
+ - **Template mode:** `language=en`, `task=transcribe`, `suppress_tokens=[]`, no prompt, greedy.
212
+ faster-whisper/CT2 exports must also be called with `suppress_tokens=[]`.
213
+ - **Speech mode:** default `suppress_tokens` and the ontology prompt (`configs/default.yaml`).
214
+
215
+ ---
216
+
217
+ ## 7. Limitations and risks
218
+
219
+ 1. **Synthetic training data.**
220
+ - Both training datasets are generated, not recorded. Behaviour on real pumps, fans or engines,
221
+ real microphones and real rooms is unknown.
222
+ - The F1 of 1.00 says the synthetic task is easy. It says nothing about the field.
223
+ 2. **The model always produces a template for non-speech audio.**
224
+ - It will describe a cough, door slam or forklift as some machine state.
225
+ - Live calls therefore only speak a diagnosis when Whisper itself says "machine/engine sound";
226
+ uploaded clips always try.
227
+ 3. **Engine numbers are poor.** RPM was off by about 1,800 on a training clip; torque values can be
228
+ malformed. Replies say "estimated", and malformed torque is dropped.
229
+ 4. **Hallucinations on noise.**
230
+ - Whisper invents text from noise and silence, including fake alarm codes biased by the domain
231
+ prompt. A guard blocks known patterns (`voice_agent/pipeline.py`).
232
+ - It is tuned on this project's clips only, so new patterns can get through.
233
+ 5. **Voice activity detection.**
234
+ - The energy VAD learns steady machinery as background.
235
+ - Impulsive noise (hammering, air guns) can still open a turn, which costs GPU time and could trigger
236
+ a diagnosis.
237
+ 6. **TTS.** Alarm codes are misread (Β§5.4). The voice is robotic and English-only.
238
+ 7. **Speech accuracy on real people is unmeasured** (Β§5.2).
239
+ 8. **Privacy.**
240
+ - Recordings contain voices, and transcripts may contain names or plant details.
241
+ - The server never logs transcript text; `recording/` is mode 0700 with 0600 files.
242
+ - There is no diarisation or PII redaction stage.
243
+ 9. **Single GPU.** One RTX 5070 serves all calls (`MAX_CONCURRENT_CALLS=4`).
244
+
245
+ ---
246
+
247
+ ## 8. Reproducibility
248
+
249
+ | Item | Value |
250
+ |---|---|
251
+ | Base weights sha256 | `a8e94b85976e5864ba3e9525c7e6c83b2a1eca42d4b797a0c7c24d778e40fd95` |
252
+ | Validation subset ids sha256 | `16e9f9af5d09f54b3209ddb8ba98757e610ec3206797849144470c573345aaa7` |
253
+ | Full lineage | `whisper_ft/out/whisper-lora/main/adapter/lineage.json` (config, CLI, manifests, package versions) |
254
+ | TTS model | `facebook/mms-tts-eng`, commit `c71de0fe7204c83f1c10820a7d696d0b450048ba` (`models/mms-tts-eng/tts_lock.json`) |
255
+ | Training command | `cd whisper_ft && python scripts/train_whisper.py --run-name main` (`configs/train.yaml`) |
256
+
257
+ ---
258
+
259
+ ## 9. Licences
260
+
261
+ | Component | Licence | Effect |
262
+ |---|---|---|
263
+ | whisper-large-v3 | Apache-2.0 | Permissive |
264
+ | AnomalyMachine-50K | CC-BY-4.0 | Attribution required |
265
+ | Procedural Engine Sounds | **CC-BY-NC-4.0** | **The adapter, merged model and CT2 export are non-commercial** (`lineage.json: non_commercial: true`) |
266
+ | MMS-TTS (`facebook/mms-tts-eng`) | **CC-BY-NC-4.0** | Voice output is non-commercial |
267
+
268
+ For commercial use:
269
+ - Retrain without the engine data.
270
+ - Replace the TTS backend (e.g. Piper with a permissively licensed voice, via `voice_agent/tts.py BACKENDS`).
271
+ - Get legal review (project plan item Q18).
272
+
273
+ ---
274
+
275
+ ## 10. Open items
276
+
277
+ - [ ] Evaluate on the **test** split and report per-field, per-machine and per-SNR accuracy, plus engine
278
+ tolerance metrics.
279
+ - [ ] Evaluate speech WER on **real operator recordings** (accents, PPE, factory noise).
280
+ - [ ] Evaluate diagnosis on **real machine recordings** with ground truth.
281
+ - [ ] Neural VAD (e.g. Silero) for impulsive factory noise.
282
+ - [ ] A clearer TTS for codes, or show codes on screen as well.
283
+ - [ ] Decide whether to retrain without the non-commercial engine data.
284
  ---
285
  license: mit
286
  ---