phamhai commited on
Commit
077dee4
·
verified ·
1 Parent(s): a001cf7

Upload code/run_asr_v3.sh with huggingface_hub

Browse files
Files changed (1) hide show
  1. code/run_asr_v3.sh +33 -0
code/run_asr_v3.sh ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # ASR v3 = PhoWhisper-large-ft-v1 continued on train audio (dev300 excluded) + filtered VieNeu-TTS speech of synth texts.
3
+ # Ship only if dev300 beam-4 WER beats v1 (11.89% on the 875 dev clips).
4
+ set -x
5
+ . ~/venv/bin/activate; cd ~/lifemate
6
+ D=~/data/train+public_test; V1=~/dctx/models/asr; OUT=~/asr_v3
7
+ [ -s ~/tts_v1/extra_ok.jsonl ] || python tts_filter.py --asr $V1 --inp ~/tts_v1/extra.jsonl --out ~/tts_v1/extra_ok.jsonl --max-wer 0.3
8
+ [ -f $OUT/config.json ] || python asr_ft.py --root $D --model $V1 --exclude dev300.txt --out $OUT --epochs 2 --lr 5e-6 --bs 16 --holdout-every 0 --extra ~/tts_v1/extra_ok.jsonl > ~/asr_v3_train.log 2>&1
9
+ python asr.py --root $D --split train --ids dev300.txt --model $OUT --out ~/asr_dev_v3.json --nbest 2 --beams 4 > ~/asr_dev_v3.log 2>&1
10
+ python asr.py --root $D --split train --ids dev300.txt --model $V1 --out ~/asr_dev_v1.json --nbest 2 --beams 4 > ~/asr_dev_v1.log 2>&1
11
+ python - <<'PY'
12
+ import json, re, unicodedata
13
+ D = "/home/hai/data/train+public_test"; ids = {l.strip() for l in open("dev300.txt")}
14
+ gold = {}
15
+ for r in map(json.loads, open(f"{D}/train/train.jsonl", encoding="utf-8")):
16
+ if r["id"] in ids:
17
+ gold[r["audio"]] = r["audio_text"]
18
+ for t in r["history"]:
19
+ if t.get("audio"): gold[t["audio"]] = t["audio_text"]
20
+ tok = lambda s: re.findall(r"[^\W_]+", unicodedata.normalize("NFC", s.lower()))
21
+ def wer(r, h):
22
+ d = list(range(len(h) + 1))
23
+ for i in range(1, len(r) + 1):
24
+ q, d[0] = d[0], i
25
+ for j in range(1, len(h) + 1): q, d[j] = d[j], min(d[j] + 1, d[j - 1] + 1, q + (r[i - 1] != h[j - 1]))
26
+ return d[-1]
27
+ for n in ["v1", "v3"]:
28
+ h = json.load(open(f"/home/hai/asr_dev_{n}.json", encoding="utf-8")); E = N = 0
29
+ for k, g in gold.items():
30
+ if k in h: gt = tok(g); E += wer(gt, tok(h[k])); N += len(gt)
31
+ print(f"DEV300 WER {n}: {E / N:.2%} ({len(h)} clips)")
32
+ PY
33
+ echo ASRV3_DONE