Datasets:
Download scripts/score_and_embed.py from booleai/librispeech-test-clean-whisper-medium-transcripts: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/datasets/booleai/librispeech-test-clean-whisper-medium-transcripts/resolve/main/scripts/score_and_embed.py
- Command line
-
hf download hf://datasets/booleai/librispeech-test-clean-whisper-medium-transcripts/scripts/score_and_embed.py
-
curl -L -o score_and_embed.py https://huggingface.co/datasets/booleai/librispeech-test-clean-whisper-medium-transcripts/resolve/main/scripts/score_and_embed.py
1.6 kB
| """Compute corpus WER with jiwer after Whisper's EnglishTextNormalizer, embed transcripts, write parquet.""" | |
| import json, time, jiwer, torch | |
| from transformers import WhisperTokenizer | |
| from sentence_transformers import SentenceTransformer | |
| from datasets import Dataset | |
| torch.set_num_threads(8) | |
| rows = json.load(open("run.rows.json")); stats = json.load(open("run.stats.json")) | |
| norm = WhisperTokenizer.from_pretrained(stats["model"]).normalize # Whisper EnglishTextNormalizer | |
| refs = [norm(r["reference"]) for r in rows]; hyps = [norm(r["transcript"]) for r in rows] | |
| m = jiwer.process_words(refs, hyps) | |
| for r, a, b in zip(rows, refs, hyps): | |
| r["reference_normalized"], r["transcript_normalized"] = a, b | |
| r["wer"] = jiwer.wer(a, b) if a else None | |
| raw = jiwer.wer([r["reference"].lower() for r in rows], [r["transcript"].lower() for r in rows]) | |
| st = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2", device="cpu"); t0 = time.time() | |
| emb = st.encode([r["transcript"] for r in rows], batch_size=64, normalize_embeddings=True); et = time.time() - t0 | |
| for r, e in zip(rows, emb): r["embedding"] = e.tolist() | |
| Dataset.from_list(rows).to_parquet("train.parquet") | |
| stats.update({"wer_normalized": m.wer, "substitutions": m.substitutions, "deletions": m.deletions, "insertions": m.insertions, | |
| "reference_words": m.hits + m.substitutions + m.deletions, "wer_lowercase_only_unnormalized": raw, | |
| "embed_model": "sentence-transformers/all-MiniLM-L6-v2", "embed_seconds": round(et, 2)}) | |
| json.dump(stats, open("run_stats.json", "w"), indent=1); print(json.dumps(stats, indent=1)) | |