muruganmath commited on
Commit
36ba721
·
verified ·
1 Parent(s): e2f4499

Add trained LoRA adapter (main), tokenizer/processor, lineage, standalone inference and model card

Browse files
README.md CHANGED
@@ -91,7 +91,7 @@ are CC-BY-NC-4.0 ([§9](#9-licences)).
91
 
92
  | | |
93
  |---|---|
94
- | **Model** | `whisper_ft/out/whisper-lora/main/adapter`: LoRA adapter for `openai/whisper-large-v3` |
95
  | **Base** | `openai/whisper-large-v3`, commit `06f233fe06e710322aca913c1bc4249a0d71fce1`, Apache-2.0, local hash-locked copy `models/whisper-large-v3` |
96
  | **Trained** | 2026-11-08 18:44 → 2026-11-09 03:40 UTC (8 h 56 min, one RTX 5070 12 GB) |
97
  | **Task** | (1) Speech → text (inherited from the base). (2) Machine sound → templated text description (what the adapter learned) |
@@ -281,10 +281,64 @@ so there are no pauses between code characters.
281
 
282
  ## 6. How to run inference
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  ### 6.1 Quick start: audio file in → voice file out
285
 
286
  One command creates the environment on its first run (skipping steps already done), then answers the
287
- audio with a spoken reply: [run_voice_inference.sh](run_voice_inference.sh).
288
 
289
  ```bash
290
  cd finetune_whisper
 
91
 
92
  | | |
93
  |---|---|
94
+ | **Model** | [`muruganmath/Machine-fault-detector`](https://huggingface.co/muruganmath/Machine-fault-detector): LoRA adapter for `openai/whisper-large-v3` (project path `whisper_ft/out/whisper-lora/main/adapter`) |
95
  | **Base** | `openai/whisper-large-v3`, commit `06f233fe06e710322aca913c1bc4249a0d71fce1`, Apache-2.0, local hash-locked copy `models/whisper-large-v3` |
96
  | **Trained** | 2026-11-08 18:44 → 2026-11-09 03:40 UTC (8 h 56 min, one RTX 5070 12 GB) |
97
  | **Task** | (1) Speech → text (inherited from the base). (2) Machine sound → templated text description (what the adapter learned) |
 
281
 
282
  ## 6. How to run inference
283
 
284
+ ### 6.0 From the Hugging Face Hub (this repository)
285
+
286
+ Files in this repository:
287
+
288
+ | File | Contents |
289
+ |---|---|
290
+ | `adapter_model.safetensors`, `adapter_config.json` | The trained LoRA weights (231 MB) and their configuration |
291
+ | `tokenizer.json`, `tokenizer_config.json`, `processor_config.json` | Whisper tokenizer and feature extractor (128 mel bins) |
292
+ | `lineage.json` | Training config, data manifests and hashes, metrics, package versions |
293
+ | `inference.py`, `diagnosis.py`, `tts_text.py`, `requirements.txt` | Standalone inference: audio → diagnosis or transcript → spoken reply WAV |
294
+
295
+ The base model (`openai/whisper-large-v3`) and the voice (`facebook/mms-tts-eng`) download from their own
296
+ repositories on first use.
297
+
298
+ ```bash
299
+ git clone https://huggingface.co/muruganmath/Machine-fault-detector && cd Machine-fault-detector
300
+ python -m venv .venv && . .venv/bin/activate # or: conda create -n mfd python=3.11 -y && conda activate mfd
301
+ pip install -r requirements.txt
302
+ python inference.py clip.wav # prints the result, writes clip_reply.wav
303
+ python inference.py clip.wav --no-voice # text only
304
+ ```
305
+
306
+ Output on a machine clip, and on speech (verified 2026-11-12):
307
+
308
+ ```
309
+ [ 0.0s] machine model: machine: fan; condition: high load; status: anomalous; fault: overheating; noise: low noise
310
+ reply: Sound check. This is a fan under high load. It sounds abnormal. Possible fault: overheating. The recording has low background noise.
311
+ [ 0.0s] speech model: Hello agent, the compressor on line 2 is making a grinding noise, please check it.
312
+ reply: I heard: Hello agent, the compressor on line 2 is making a grinding noise, please check it.
313
+ ```
314
+
315
+ In Python, for the template text only:
316
+
317
+ ```python
318
+ import copy, torch, soundfile as sf
319
+ from peft import PeftModel
320
+ from transformers import WhisperForConditionalGeneration, WhisperProcessor
321
+
322
+ proc = WhisperProcessor.from_pretrained("openai/whisper-large-v3")
323
+ model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v3", dtype=torch.bfloat16)
324
+ model = PeftModel.from_pretrained(model, "muruganmath/Machine-fault-detector").merge_and_unload().to("cuda").eval()
325
+ gc = copy.deepcopy(model.generation_config)
326
+ gc.suppress_tokens, gc.language, gc.task = [], "en", "transcribe" # ':' and ';' must not be suppressed
327
+
328
+ audio, sr = sf.read("clip.wav", dtype="float32") # 16 kHz mono, <= 30 s
329
+ audio = audio * (10 ** (-1 / 20) / abs(audio).max()) # peak -1 dBFS, as in training
330
+ feats = proc.feature_extractor([audio], sampling_rate=16000, return_tensors="pt").input_features
331
+ out = model.generate(input_features=feats.to("cuda", torch.bfloat16), generation_config=gc, max_new_tokens=128)
332
+ print(proc.tokenizer.batch_decode(out, skip_special_tokens=True)[0])
333
+ ```
334
+
335
+ Sections 6.1–6.3 use the full project source (voice agent, ACS server, scripts), which is **not** part of
336
+ this repository.
337
+
338
  ### 6.1 Quick start: audio file in → voice file out
339
 
340
  One command creates the environment on its first run (skipping steps already done), then answers the
341
+ audio with a spoken reply: `run_voice_inference.sh` (project source).
342
 
343
  ```bash
344
  cd finetune_whisper
adapter_config.json ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "alora_invocation_tokens": null,
3
+ "alpha_pattern": {},
4
+ "arrow_config": null,
5
+ "auto_mapping": {
6
+ "base_model_class": "WhisperForConditionalGeneration",
7
+ "parent_library": "transformers.models.whisper.modeling_whisper"
8
+ },
9
+ "base_model_name_or_path": "openai/whisper-large-v3",
10
+ "bias": "none",
11
+ "corda_config": null,
12
+ "ensure_weight_tying": false,
13
+ "eva_config": null,
14
+ "exclude_modules": null,
15
+ "fan_in_fan_out": false,
16
+ "inference_mode": true,
17
+ "init_lora_weights": true,
18
+ "kasa_config": null,
19
+ "layer_replication": null,
20
+ "layers_pattern": null,
21
+ "layers_to_transform": null,
22
+ "loftq_config": {},
23
+ "lora_alpha": 64,
24
+ "lora_bias": false,
25
+ "lora_dropout": 0.05,
26
+ "lora_ga_config": null,
27
+ "megatron_config": null,
28
+ "megatron_core": "megatron.core",
29
+ "modules_to_save": null,
30
+ "monteclora_config": null,
31
+ "peft_type": "LORA",
32
+ "peft_version": "0.21.2",
33
+ "qalora_group_size": 16,
34
+ "r": 32,
35
+ "rank_pattern": {},
36
+ "revision": null,
37
+ "target_modules": [
38
+ "v_proj",
39
+ "fc1",
40
+ "k_proj",
41
+ "out_proj",
42
+ "fc2",
43
+ "q_proj"
44
+ ],
45
+ "target_parameters": null,
46
+ "task_type": null,
47
+ "trainable_token_indices": null,
48
+ "use_bdlora": null,
49
+ "use_dora": false,
50
+ "use_qalora": false,
51
+ "use_rslora": false,
52
+ "velora_config": null
53
+ }
adapter_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e89319c228cdd6060b813934b9a8f39fc47271628b6c0ad04267f0c1f033df3
3
+ size 230831688
diagnosis.py ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Machine-sound diagnosis from the whisper_ft adapter -> a sentence the agent can speak.
2
+
3
+ The whisper_ft main adapter (whisper_ft/out/whisper-lora/main) was trained to describe
4
+ non-speech audio with one of three templates (whisper_ft/configs/templates.yaml):
5
+
6
+ anomaly: "machine: fan; condition: high load; status: anomalous; fault: overheating; noise: clean"
7
+ engine: "engine sound; rpm mean 2020 range 920 to 3860; torque mean 467 nm"
8
+ ego: "activity: ...; task: ...; view: ...[; notes: ...]"
9
+
10
+ parse_diagnosis() turns the decoded text into fields (None if it is not a complete template),
11
+ describe() turns the fields into plain English for TTS, e.g.
12
+ "Sound check. This is a fan under high load. It sounds abnormal. Possible fault: overheating."
13
+ Wording was chosen by synthesizing with MMS-TTS and transcribing back with Whisper (2026-11-12):
14
+ MMS cannot say "engine" ("Insan", "Ed Sheik") or "idling" ("piling"); "machine sound check"
15
+ came back as "matching sound check". "motor", "at idle" and "Sound check. This is ..." survive.
16
+ The diagnosis is the model's estimate (anomaly F1 1.0, field accuracy 0.60 on validation,
17
+ whisper_ft train_summary.json): describe() says "possible" fault, never a certainty.
18
+ """
19
+
20
+ from __future__ import annotations
21
+
22
+ import re
23
+ from dataclasses import dataclass, field
24
+
25
+
26
+ @dataclass
27
+ class Diagnosis:
28
+ kind: str # "anomaly" | "engine" | "activity"
29
+ fields: dict = field(default_factory=dict)
30
+ raw: str = ""
31
+
32
+
33
+ _ENGINE = re.compile(
34
+ r"^\s*engine sound\s*;\s*rpm mean\s+(-?\d+)\s+range\s+(-?\d+)\s+to\s+(-?\d+)\s*(?:;(.*))?$",
35
+ re.IGNORECASE | re.DOTALL)
36
+ _TORQUE = re.compile(r"^\s*torque mean\s+(-?\d+)\s*nm\s*\.?\s*$", re.IGNORECASE)
37
+
38
+
39
+ def _kv(text: str) -> dict:
40
+ out = {}
41
+ for part in text.split(";"):
42
+ if ":" in part:
43
+ k, v = part.split(":", 1)
44
+ out[k.strip().lower()] = v.strip().strip(".").lower()
45
+ return out
46
+
47
+
48
+ def parse_diagnosis(text: str) -> Diagnosis | None:
49
+ text = (text or "").strip()
50
+ m = _ENGINE.match(text)
51
+ if m:
52
+ mean, lo, hi = (int(g) for g in m.groups()[:3])
53
+ f = {"rpm_mean": mean, "rpm_min": lo, "rpm_max": hi}
54
+ t = _TORQUE.match(m.group(4) or "")
55
+ if t: # a garbled torque ("6-7-0-8 .", seen 2026-11-12) is dropped, not guessed
56
+ f["torque_mean"] = int(t.group(1))
57
+ if not lo <= mean <= hi: # inconsistent numbers: not a usable diagnosis
58
+ return None
59
+ return Diagnosis("engine", f, text)
60
+ f = _kv(text)
61
+ if f.get("machine") and f.get("condition") and f.get("status") in {"normal", "anomalous"}:
62
+ return Diagnosis("anomaly", f, text)
63
+ if f.get("activity") and f.get("task"):
64
+ return Diagnosis("activity", f, text)
65
+ return None
66
+
67
+
68
+ def _article(noun: str) -> str:
69
+ return ("an " if noun[:1] in "aeiou" else "a ") + noun
70
+
71
+
72
+ def _condition(c: str) -> str:
73
+ if c == "idle":
74
+ return "at idle"
75
+ if c.endswith("load"):
76
+ return "under " + c
77
+ return "in " + c + " condition"
78
+
79
+
80
+ def _num(n: int) -> str:
81
+ return ("minus " + str(-n)) if n < 0 else str(n)
82
+
83
+
84
+ def describe(d: Diagnosis) -> str:
85
+ f = d.fields
86
+ if d.kind == "anomaly":
87
+ s = f"Sound check. This is {_article(f['machine'])} {_condition(f['condition'])}."
88
+ if f["status"] == "anomalous":
89
+ s += " It sounds abnormal."
90
+ fault = f.get("fault", "none")
91
+ if fault and fault != "none":
92
+ s += f" Possible fault: {fault}."
93
+ else:
94
+ s += " It sounds normal."
95
+ noise = f.get("noise", "")
96
+ if noise and noise not in {"clean", "none"}:
97
+ s += f" The recording has {noise.replace(' noise', '')} background noise."
98
+ return s
99
+ if d.kind == "engine":
100
+ # "estimated": the adapter's numbers can be far off (505_Engine-C: said mean 4660 RPM, label 2870)
101
+ s = (f"Sound check. This is a motor. The estimated average speed is {_num(f['rpm_mean'])} RPM, "
102
+ f"ranging from {_num(f['rpm_min'])} to {_num(f['rpm_max'])} RPM.")
103
+ if "torque_mean" in f:
104
+ s += f" The estimated average torque is {_num(f['torque_mean'])} newton metres."
105
+ return s
106
+ s = f"Sound check. Workshop activity: {f['activity']}. Task: {f['task']}."
107
+ if f.get("view"):
108
+ s += f" View: {f['view']}."
109
+ if f.get("notes"):
110
+ s += f" Notes: {f['notes']}."
111
+ return s
inference.py ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """Machine-fault-detector: audio file in -> diagnosis (or transcript) -> spoken reply WAV.
3
+
4
+ pip install -r requirements.txt
5
+ python inference.py clip.wav # -> clip_reply.wav + printed text
6
+ python inference.py clip.wav --out reply.wav --no-voice
7
+
8
+ Loads openai/whisper-large-v3 + this LoRA adapter, decodes like training (16 kHz mono,
9
+ <= 30 s chunks, peak -1 dBFS, greedy, suppress_tokens=[] because ':' and ';' are template
10
+ tokens). Per chunk:
11
+ * a complete machine template -> "Sound check. This is a fan under high load. ..."
12
+ * otherwise speech -> "I heard: <transcript>"
13
+ * noise / known hallucination -> silent
14
+ The reply is spoken with facebook/mms-tts-eng (CC-BY-NC-4.0). Research prototype: trained
15
+ on synthetic machine sounds only; do not use for maintenance or safety decisions.
16
+ """
17
+
18
+ import argparse
19
+ import copy
20
+ import re
21
+ import sys
22
+ from math import gcd
23
+ from pathlib import Path
24
+
25
+ import numpy as np
26
+ import soundfile as sf
27
+ import torch
28
+ from scipy.signal import resample_poly
29
+
30
+ HERE = Path(__file__).resolve().parent
31
+ sys.path.insert(0, str(HERE))
32
+ from diagnosis import describe, parse_diagnosis # noqa: E402
33
+ from tts_text import speakable, split_sentences # noqa: E402
34
+
35
+ SR = 16000
36
+ REPO = "muruganmath/Machine-fault-detector"
37
+ # outputs that are noise, not speech (measured on the training project's clips)
38
+ NOT_SPEECH = re.compile(r"^\s*(?:(?:(?:machine|engine)(?:\s+sounds?)?)[\s.,;:]*)+$", re.I)
39
+ HALLUCINATIONS = {"you", "so", "the", "okay", "ok", "bye", "uh", "um", "hmm", "oh", "thank you",
40
+ "thanks", "thank you very much", "thanks for watching", "thank you for watching"}
41
+
42
+
43
+ def load_audio(path: str) -> np.ndarray:
44
+ x, sr = sf.read(path, dtype="float32", always_2d=True)
45
+ x = x.mean(axis=1)
46
+ if sr != SR:
47
+ g = gcd(sr, SR)
48
+ x = resample_poly(x, SR // g, sr // g).astype(np.float32)
49
+ return x
50
+
51
+
52
+ def chunks(x: np.ndarray, max_s: float = 30.0):
53
+ n = int(max_s * SR)
54
+ for i in range(0, len(x), n):
55
+ c = x[i:i + n]
56
+ if c.size >= SR and 20 * np.log10(max(float(np.sqrt(np.mean(c ** 2))), 1e-10)) >= -60.0:
57
+ yield i / SR, c # same rejection as training: < 1 s or silent
58
+
59
+
60
+ class Detector:
61
+ def __init__(self, repo: str = REPO, base: str = "openai/whisper-large-v3", device: str | None = None):
62
+ from peft import PeftModel
63
+ from transformers import WhisperForConditionalGeneration, WhisperProcessor
64
+
65
+ self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
66
+ self.dtype = torch.bfloat16 if self.device == "cuda" else torch.float32
67
+ self.proc = WhisperProcessor.from_pretrained(base)
68
+ model = WhisperForConditionalGeneration.from_pretrained(base, dtype=self.dtype, attn_implementation="sdpa")
69
+ self.model = PeftModel.from_pretrained(model, repo).merge_and_unload().to(self.device).eval()
70
+ gc = copy.deepcopy(self.model.generation_config)
71
+ gc.suppress_tokens, gc.language, gc.task, gc.forced_decoder_ids = [], "en", "transcribe", None
72
+ self.gen_config = gc
73
+
74
+ @torch.inference_mode()
75
+ def decode(self, chunk: np.ndarray) -> str:
76
+ x = chunk * (10 ** (-1.0 / 20) / max(float(np.abs(chunk).max()), 1e-9)) # peak -1 dBFS
77
+ feats = self.proc.feature_extractor([x], sampling_rate=SR, return_tensors="pt").input_features
78
+ out = self.model.generate(input_features=feats.to(self.device, self.dtype), generation_config=self.gen_config,
79
+ max_new_tokens=128, num_beams=1)
80
+ return self.proc.tokenizer.batch_decode(out, skip_special_tokens=True)[0].strip()
81
+
82
+
83
+ def reply_for(text: str) -> tuple[str, str | None]:
84
+ """(kind, reply text or None)."""
85
+ d = parse_diagnosis(text)
86
+ if d is not None:
87
+ return "machine", describe(d)
88
+ key = re.sub(r"\s+", " ", re.sub(r"[^a-z0-9' ]", " ", text.lower())).strip()
89
+ if not re.search(r"[A-Za-z0-9]", text) or NOT_SPEECH.match(text) or key in HALLUCINATIONS:
90
+ return "noise", None
91
+ return "speech", f"I heard: {text}"
92
+
93
+
94
+ class Voice:
95
+ def __init__(self, repo: str = "facebook/mms-tts-eng", device: str | None = None):
96
+ from transformers import AutoTokenizer, VitsModel
97
+ self.device = device or ("cuda" if torch.cuda.is_available() else "cpu")
98
+ self.model = VitsModel.from_pretrained(repo).to(self.device).eval()
99
+ self.tok = AutoTokenizer.from_pretrained(repo)
100
+ self.sr = int(self.model.config.sampling_rate)
101
+
102
+ @torch.inference_mode()
103
+ def speak(self, text: str) -> np.ndarray:
104
+ parts, gap = [], np.zeros(int(0.12 * self.sr), np.float32)
105
+ for s in split_sentences(speakable(text)):
106
+ ids = self.tok(s, return_tensors="pt").to(self.device)
107
+ if ids["input_ids"].shape[-1] == 0:
108
+ continue
109
+ torch.manual_seed(0) # VITS is stochastic; keep replies reproducible
110
+ parts += [self.model(**ids).waveform[0].float().cpu().numpy(), gap]
111
+ if not parts:
112
+ return np.zeros(0, np.float32)
113
+ y = np.concatenate(parts[:-1])
114
+ return (y * min(1.0, 0.9 / max(float(np.abs(y).max()), 1e-9))).astype(np.float32)
115
+
116
+
117
+ def main():
118
+ ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
119
+ ap.add_argument("audio")
120
+ ap.add_argument("--out", help="reply WAV (default: <audio>_reply.wav next to the input)")
121
+ ap.add_argument("--repo", default=REPO, help="adapter repo id or local folder")
122
+ ap.add_argument("--base", default="openai/whisper-large-v3", help="base model repo id or local folder")
123
+ ap.add_argument("--tts", default="facebook/mms-tts-eng", help="TTS repo id or local folder")
124
+ ap.add_argument("--no-voice", action="store_true", help="print the text only")
125
+ args = ap.parse_args()
126
+
127
+ det = Detector(args.repo, args.base)
128
+ replies = []
129
+ for t0, c in chunks(load_audio(args.audio)):
130
+ text = det.decode(c)
131
+ kind, reply = reply_for(text)
132
+ print(f"[{t0:6.1f}s] {kind:7s} model: {text}")
133
+ print(f"{'':16}reply: {reply or '(silent)'}")
134
+ if reply:
135
+ replies.append(reply)
136
+ if args.no_voice or not replies:
137
+ return
138
+ voice = Voice(args.tts)
139
+ gap = np.zeros(int(0.4 * voice.sr), np.float32)
140
+ wav = np.concatenate([np.concatenate([voice.speak(r), gap]) for r in replies])[: -gap.size]
141
+ out = args.out or str(Path(args.audio).with_name(Path(args.audio).stem + "_reply.wav"))
142
+ sf.write(out, wav, voice.sr, subtype="PCM_16")
143
+ print(f"voice reply: {out} ({wav.size / voice.sr:.1f} s)")
144
+
145
+
146
+ if __name__ == "__main__":
147
+ main()
lineage.json ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "run_name": "main",
3
+ "created_utc": "2026-11-08T18:44:24Z",
4
+ "base_model": {
5
+ "path": "models/whisper-large-v3",
6
+ "repo_id": "openai/whisper-large-v3",
7
+ "commit_sha": "06f233fe06e710322aca913c1bc4249a0d71fce1",
8
+ "license": "apache-2.0",
9
+ "weights_sha256": {
10
+ "model.safetensors": "a8e94b85976e5864ba3e9525c7e6c83b2a1eca42d4b797a0c7c24d778e40fd95"
11
+ }
12
+ },
13
+ "manifests": {
14
+ "train": {
15
+ "path": "whisper_ft/manifests/train.jsonl",
16
+ "sha256": "793e412837b58ce9604a380b23090107de9b87244ffae55823bf9b6d220c838f",
17
+ "rows": 24497
18
+ },
19
+ "val": {
20
+ "path": "whisper_ft/manifests/val.jsonl",
21
+ "sha256": "44c8ad4bc2691e9a4428f85b8ae8c8a1918c38e6439e2d87d4c82159438572e3",
22
+ "rows": 8217
23
+ },
24
+ "test": {
25
+ "path": "whisper_ft/manifests/test.jsonl",
26
+ "sha256": "e5510f27fe6995133f29bca7fc0285fbf34276bb7225f13839c874de744e48aa",
27
+ "rows": 8216
28
+ }
29
+ },
30
+ "train_rows_used": 24497,
31
+ "train_rows_per_dataset": {
32
+ "anomaly": 20000,
33
+ "engine": 4497
34
+ },
35
+ "eval_subset_rows": 600,
36
+ "eval_subset_ids_sha256": "16e9f9af5d09f54b3209ddb8ba98757e610ec3206797849144470c573345aaa7",
37
+ "dataset_licenses": {
38
+ "anomaly": {
39
+ "hf_id": "mandipgoswami/AnomalyMachine-50K",
40
+ "license": "cc-by-4.0"
41
+ },
42
+ "engine": {
43
+ "hf_id": "huggingbear12/procedural-engine-sounds",
44
+ "license": "cc-by-nc-4.0",
45
+ "note": "NON-COMMERCIAL: models trained on this data inherit the NC restriction"
46
+ }
47
+ },
48
+ "non_commercial": true,
49
+ "config": {
50
+ "model": {
51
+ "base_path": "../models/whisper-large-v3",
52
+ "language": "en",
53
+ "task": "transcribe",
54
+ "quantization": "8bit",
55
+ "attn_implementation": "sdpa",
56
+ "apply_spec_augment": false,
57
+ "finetuned_decoding": true
58
+ },
59
+ "lora": {
60
+ "r": 32,
61
+ "alpha": 64,
62
+ "dropout": 0.05,
63
+ "target_modules": [
64
+ "q_proj",
65
+ "k_proj",
66
+ "v_proj",
67
+ "out_proj",
68
+ "fc1",
69
+ "fc2"
70
+ ],
71
+ "scope": "all"
72
+ },
73
+ "data": {
74
+ "train_manifest": "manifests/train.jsonl",
75
+ "val_manifest": "manifests/val.jsonl",
76
+ "test_manifest": "manifests/test.jsonl",
77
+ "max_label_tokens": 128,
78
+ "eval_samples": 600,
79
+ "seed": 42
80
+ },
81
+ "training": {
82
+ "output_root": "out/whisper-lora",
83
+ "per_device_train_batch_size": 4,
84
+ "per_device_eval_batch_size": 8,
85
+ "gradient_accumulation_steps": 8,
86
+ "learning_rate": 0.0001,
87
+ "warmup_ratio": 0.05,
88
+ "lr_scheduler_type": "cosine",
89
+ "num_train_epochs": 3,
90
+ "weight_decay": 0.0,
91
+ "bf16": true,
92
+ "gradient_checkpointing": true,
93
+ "optim": "adamw_bnb_8bit",
94
+ "eval_steps": 500,
95
+ "save_steps": 500,
96
+ "save_total_limit": 3,
97
+ "predict_with_generate": true,
98
+ "generation_max_length": 128,
99
+ "metric_for_best_model": "wer",
100
+ "greater_is_better": false,
101
+ "load_best_model_at_end": true,
102
+ "remove_unused_columns": false,
103
+ "dataloader_num_workers": 6,
104
+ "logging_steps": 25,
105
+ "report_to": "none",
106
+ "seed": 42
107
+ },
108
+ "fallbacks": {
109
+ "batch2": {
110
+ "training.per_device_train_batch_size": 2,
111
+ "training.gradient_accumulation_steps": 16
112
+ },
113
+ "nf4": {
114
+ "model.quantization": "4bit"
115
+ },
116
+ "decoder_only": {
117
+ "lora.scope": "decoder"
118
+ },
119
+ "turbo": {
120
+ "model.base_path": "../models/whisper-large-v3-turbo"
121
+ }
122
+ }
123
+ },
124
+ "cli": [
125
+ "--run-name",
126
+ "main"
127
+ ],
128
+ "resumed_from": null,
129
+ "finished_utc": "2026-11-09T03:40:52Z",
130
+ "global_steps": 2298,
131
+ "best_checkpoint": "whisper_ft/out/whisper-lora/main/checkpoints/checkpoint-2298",
132
+ "best_metric": 0.18471849865951742,
133
+ "train_metrics": {
134
+ "train_runtime": 31899.7704,
135
+ "train_samples_per_second": 2.304,
136
+ "train_steps_per_second": 0.072,
137
+ "total_flos": 2.5945070514536448e+20,
138
+ "train_loss": 0.21723902401870182,
139
+ "epoch": 3.0,
140
+ "peak_vram_reserved_gb": 10.36,
141
+ "sec_per_step": 13.05
142
+ },
143
+ "final_eval": {
144
+ "eval_loss": 0.2756240665912628,
145
+ "eval_wer": 0.18471849865951742,
146
+ "eval_cer": 0.0795668549905838,
147
+ "eval_exact": 0.22166666666666668,
148
+ "eval_field_acc_mean": 0.5955555555555555,
149
+ "eval_anomaly_f1": 1.0,
150
+ "eval_wer_anomaly": 0.08876404494382023,
151
+ "eval_wer_engine": 0.2723076923076923,
152
+ "eval_runtime": 286.9148,
153
+ "eval_samples_per_second": 2.091,
154
+ "eval_steps_per_second": 0.261,
155
+ "epoch": 3.0,
156
+ "peak_vram_reserved_gb": 10.36,
157
+ "sec_per_step": 13.05
158
+ },
159
+ "perf": {
160
+ "optimizer_steps_timed": 2296,
161
+ "sec_per_optimizer_step_mean": 13.259,
162
+ "sec_per_optimizer_step_median": 13.276,
163
+ "peak_vram_allocated_gb": 9.23,
164
+ "peak_vram_reserved_gb": 10.36,
165
+ "peak_device_used_gb": 10.76
166
+ },
167
+ "train_wall_seconds": 31900.2,
168
+ "environment": {
169
+ "torch": "2.15.0",
170
+ "transformers": "5.22.2",
171
+ "peft": "0.21.2",
172
+ "bitsandbytes": "0.50.2",
173
+ "accelerate": "1.15.0",
174
+ "gpu": "NVIDIA GeForce RTX 5070",
175
+ "python": "3.11.18"
176
+ }
177
+ }
processor_config.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "feature_extractor": {
3
+ "chunk_length": 30,
4
+ "dither": 0.0,
5
+ "feature_extractor_type": "WhisperFeatureExtractor",
6
+ "feature_size": 128,
7
+ "hop_length": 160,
8
+ "n_fft": 400,
9
+ "n_samples": 480000,
10
+ "nb_max_frames": 3000,
11
+ "padding_side": "right",
12
+ "padding_value": 0.0,
13
+ "return_attention_mask": false,
14
+ "sampling_rate": 16000
15
+ },
16
+ "processor_class": "WhisperProcessor"
17
+ }
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ torch>=2.7
2
+ transformers>=4.46
3
+ peft>=0.13
4
+ accelerate>=1.0
5
+ soundfile>=0.12
6
+ scipy
7
+ numpy
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": "<|endoftext|>",
5
+ "clean_up_tokenization_spaces": true,
6
+ "eos_token": "<|endoftext|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|startoftranscript|>",
10
+ "<|en|>",
11
+ "<|zh|>",
12
+ "<|de|>",
13
+ "<|es|>",
14
+ "<|ru|>",
15
+ "<|ko|>",
16
+ "<|fr|>",
17
+ "<|ja|>",
18
+ "<|pt|>",
19
+ "<|tr|>",
20
+ "<|pl|>",
21
+ "<|ca|>",
22
+ "<|nl|>",
23
+ "<|ar|>",
24
+ "<|sv|>",
25
+ "<|it|>",
26
+ "<|id|>",
27
+ "<|hi|>",
28
+ "<|fi|>",
29
+ "<|vi|>",
30
+ "<|he|>",
31
+ "<|uk|>",
32
+ "<|el|>",
33
+ "<|ms|>",
34
+ "<|cs|>",
35
+ "<|ro|>",
36
+ "<|da|>",
37
+ "<|hu|>",
38
+ "<|ta|>",
39
+ "<|no|>",
40
+ "<|th|>",
41
+ "<|ur|>",
42
+ "<|hr|>",
43
+ "<|bg|>",
44
+ "<|lt|>",
45
+ "<|la|>",
46
+ "<|mi|>",
47
+ "<|ml|>",
48
+ "<|cy|>",
49
+ "<|sk|>",
50
+ "<|te|>",
51
+ "<|fa|>",
52
+ "<|lv|>",
53
+ "<|bn|>",
54
+ "<|sr|>",
55
+ "<|az|>",
56
+ "<|sl|>",
57
+ "<|kn|>",
58
+ "<|et|>",
59
+ "<|mk|>",
60
+ "<|br|>",
61
+ "<|eu|>",
62
+ "<|is|>",
63
+ "<|hy|>",
64
+ "<|ne|>",
65
+ "<|mn|>",
66
+ "<|bs|>",
67
+ "<|kk|>",
68
+ "<|sq|>",
69
+ "<|sw|>",
70
+ "<|gl|>",
71
+ "<|mr|>",
72
+ "<|pa|>",
73
+ "<|si|>",
74
+ "<|km|>",
75
+ "<|sn|>",
76
+ "<|yo|>",
77
+ "<|so|>",
78
+ "<|af|>",
79
+ "<|oc|>",
80
+ "<|ka|>",
81
+ "<|be|>",
82
+ "<|tg|>",
83
+ "<|sd|>",
84
+ "<|gu|>",
85
+ "<|am|>",
86
+ "<|yi|>",
87
+ "<|lo|>",
88
+ "<|uz|>",
89
+ "<|fo|>",
90
+ "<|ht|>",
91
+ "<|ps|>",
92
+ "<|tk|>",
93
+ "<|nn|>",
94
+ "<|mt|>",
95
+ "<|sa|>",
96
+ "<|lb|>",
97
+ "<|my|>",
98
+ "<|bo|>",
99
+ "<|tl|>",
100
+ "<|mg|>",
101
+ "<|as|>",
102
+ "<|tt|>",
103
+ "<|haw|>",
104
+ "<|ln|>",
105
+ "<|ha|>",
106
+ "<|ba|>",
107
+ "<|jw|>",
108
+ "<|su|>",
109
+ "<|yue|>",
110
+ "<|translate|>",
111
+ "<|transcribe|>",
112
+ "<|startoflm|>",
113
+ "<|startofprev|>",
114
+ "<|nospeech|>",
115
+ "<|notimestamps|>"
116
+ ],
117
+ "is_local": true,
118
+ "language": "en",
119
+ "local_files_only": false,
120
+ "model_max_length": 1000000000000000019884624838656,
121
+ "pad_token": "<|endoftext|>",
122
+ "predict_timestamps": false,
123
+ "processor_class": "WhisperProcessor",
124
+ "task": "transcribe",
125
+ "tokenizer_class": "WhisperTokenizer",
126
+ "unk_token": "<|endoftext|>"
127
+ }
tts_text.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Make Whisper output speakable for a character-level TTS (MMS-VITS has no digits).
2
+
3
+ "Alarm F007 on line 3, VFD tripped" -> "alarm eff zero zero seven on line three, vee eff dee tripped"
4
+
5
+ Codes (letters+digits) and digit strings with leading zeros are read digit by digit,
6
+ which is how operators read alarm and part numbers; plain numbers < 10000 are read
7
+ as words; ALL-CAPS acronyms are spelled out.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import re
13
+
14
+ _ONES = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
15
+ "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen",
16
+ "nineteen"]
17
+ _TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
18
+ _SYMBOLS = {"%": " percent", "&": " and ", "+": " plus ", "°": " degrees ", "#": " number ",
19
+ "/": " slash ", "@": " at "}
20
+
21
+
22
+ def _under_100(n: int) -> str:
23
+ if n < 20:
24
+ return _ONES[n]
25
+ t, o = divmod(n, 10)
26
+ return _TENS[t] + ("" if o == 0 else " " + _ONES[o])
27
+
28
+
29
+ def number_to_words(n: int) -> str:
30
+ if n < 100:
31
+ return _under_100(n)
32
+ if n < 1000:
33
+ h, r = divmod(n, 100)
34
+ return _ONES[h] + " hundred" + ("" if r == 0 else " " + _under_100(r))
35
+ th, r = divmod(n, 1000)
36
+ return _under_100(th) + " thousand" + ("" if r == 0 else " " + number_to_words(r))
37
+
38
+
39
+ # Letter names: a character-level TTS reads a lone "f" as a sound, not as the letter
40
+ # (measured: "f zero zero seven" came back from Whisper as "007").
41
+ _LETTERS = {"a": "ay", "b": "bee", "c": "see", "d": "dee", "e": "ee", "f": "eff", "g": "jee", "h": "aitch",
42
+ "i": "eye", "j": "jay", "k": "kay", "l": "el", "m": "em", "n": "en", "o": "oh", "p": "pee",
43
+ "q": "cue", "r": "ar", "s": "ess", "t": "tee", "u": "you", "v": "vee", "w": "double you",
44
+ "x": "ex", "y": "why", "z": "zed"}
45
+
46
+
47
+ def _spell(letters: str) -> str:
48
+ return " ".join(_LETTERS[ch] for ch in letters.lower())
49
+
50
+
51
+ def _digits(s: str) -> str:
52
+ return " ".join(_ONES[int(d)] for d in s)
53
+
54
+
55
+ def _read_number(s: str) -> str:
56
+ if len(s) > 1 and s.startswith("0") or len(s) > 4:
57
+ return _digits(s)
58
+ return number_to_words(int(s))
59
+
60
+
61
+ def _token(tok: str) -> str:
62
+ if re.fullmatch(r"\d+(\.\d+)?", tok):
63
+ whole, _, frac = tok.partition(".")
64
+ out = _read_number(whole)
65
+ return out + (" point " + _digits(frac) if frac else "")
66
+ if re.search(r"\d", tok) and re.search(r"[A-Za-z]", tok): # code like F007, M6x20, PN-4471A
67
+ parts = re.findall(r"[A-Za-z]+|\d+", tok)
68
+ return " ".join(_spell(p) if p.isalpha() and len(p) <= 3 else
69
+ (p.lower() if p.isalpha() else _digits(p)) for p in parts)
70
+ if re.fullmatch(r"[A-Z]{2,5}s?", tok): # VFD, PLC, HMIs
71
+ letters = tok[:-1] if tok.endswith("s") else tok
72
+ return _spell(letters) + ("s" if tok.endswith("s") else "")
73
+ if re.fullmatch(r"\d+", re.sub(r"[^\d]", "", tok) or "x") and "-" in tok: # 12-34
74
+ return " ".join(_digits(p) for p in tok.split("-") if p)
75
+ return tok
76
+
77
+
78
+ def speakable(text: str) -> str:
79
+ for sym, rep in _SYMBOLS.items():
80
+ text = text.replace(sym, rep)
81
+ out = []
82
+ for tok in re.findall(r"[A-Za-z0-9][A-Za-z0-9.\-']*[A-Za-z0-9]|[A-Za-z0-9]|[^\sA-Za-z0-9]", text):
83
+ if tok[-1] == "." and len(tok) > 1:
84
+ tok = tok[:-1]
85
+ out.append(_token(tok))
86
+ s = " ".join(out)
87
+ s = re.sub(r"\s+([,.!?;:])", r"\1", s)
88
+ s = re.sub(r"[^a-zA-Z' ,.!?;:\-]", " ", s)
89
+ return re.sub(r"\s+", " ", s).strip().lower()
90
+
91
+
92
+ def split_sentences(text: str, max_chars: int = 200) -> list[str]:
93
+ """Split into sentence-sized pieces so the TTS can start speaking early."""
94
+ parts = [p.strip() for p in re.split(r"(?<=[.!?;])\s+", text) if p.strip()]
95
+ out: list[str] = []
96
+ for p in parts:
97
+ while len(p) > max_chars:
98
+ cut = p.rfind(",", 0, max_chars)
99
+ cut = cut if cut > 0 else p.rfind(" ", 0, max_chars)
100
+ cut = cut if cut > 0 else max_chars
101
+ out.append(p[:cut + 1].strip())
102
+ p = p[cut + 1:].strip()
103
+ if p:
104
+ out.append(p)
105
+ return out