Download phase2_corrected/code/decode_devhard_joint.py from Pricile/waxal2026-backup: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/Pricile/waxal2026-backup/resolve/main/phase2_corrected/code/decode_devhard_joint.py
- Command line
-
hf download hf://Pricile/waxal2026-backup/phase2_corrected/code/decode_devhard_joint.py
-
curl -L -o decode_devhard_joint.py https://huggingface.co/Pricile/waxal2026-backup/resolve/main/phase2_corrected/code/decode_devhard_joint.py
1.05 kB
| import json, soundfile as sf, torch | |
| from transformers import AutoModelForCTC, AutoProcessor | |
| M="/root/models/joint_cont_best" | |
| proc=AutoProcessor.from_pretrained(M) | |
| model=AutoModelForCTC.from_pretrained(M,torch_dtype=torch.bfloat16).cuda().eval() | |
| rows=[json.loads(l) for l in open("/root/devhard/devhard_linsna.jsonl")] | |
| def norm(s): return " ".join(str(s).replace("|"," ").split()) | |
| out=[] | |
| with torch.inference_mode(): | |
| for i in range(0,len(rows),8): | |
| b=rows[i:i+8] | |
| au=[sf.read(r["audio"],dtype="float32")[0] for r in b] | |
| x=proc(au,sampling_rate=16000,return_tensors="pt",padding=True) | |
| x={k:v.to("cuda",dtype=torch.bfloat16 if v.dtype==torch.float32 else v.dtype) for k,v in x.items()} | |
| pid=model(**x).logits.float().argmax(-1).cpu().numpy() | |
| for r,h in zip(b,proc.batch_decode(pid)): | |
| out.append({"id":r["id"],"lang":r.get("lang"),"ref":r["text"],"hyp":norm(h)}) | |
| json.dump(out,open("/root/devhard_joint_hyps.json","w",encoding="utf-8"),ensure_ascii=False) | |
| print("DECODE_DEVHARD_DONE",len(out)) | |