Views
No views yet
1import torch
2from transformers import WhisperForConditionalGeneration, WhisperProcessor
3
4#Load the processor and model.
5MODEL_NAME="language-and-voice-lab/whisper-large-icelandic-62640-steps-967h"
6processor = WhisperProcessor.from_pretrained(MODEL_NAME)
7model = WhisperForConditionalGeneration.from_pretrained(MODEL_NAME).to("cuda")
8
9#Load the dataset
10from datasets import load_dataset, load_metric, Audio
11ds=load_dataset("language-and-voice-lab/samromur_children",split='test')
12
13#Downsample to 16kHz
14ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
15
16#Process the dataset
17def map_to_pred(batch):
18 audio = batch["audio"]
19 input_features = processor(audio["array"], sampling_rate=audio["sampling_rate"], return_tensors="pt").input_features
20 batch["reference"] = processor.tokenizer._normalize(batch['normalized_text'])
21
22 with torch.no_grad():
23 predicted_ids = model.generate(input_features.to("cuda"))[0]
24
25 transcription = processor.decode(predicted_ids)
26 batch["prediction"] = processor.tokenizer._normalize(transcription)
27
28 return batch
29
30#Do the evaluation
31result = ds.map(map_to_pred)
32
33#Compute the overall WER now.
34from evaluate import load
35
36wer = load("wer")
37WER=100 * wer.compute(references=result["reference"], predictions=result["prediction"])
38print(WER)1@inproceedings{mena2024samromur,
2 title={Samr{\'o}mur Millj{\'o}n: An ASR Corpus of One Million Verified Read Prompts in Icelandic},
3 author={Mena, Carlos Daniel Hernandez and Gunnarsson, {\TH}orsteinn Da{\dh}i and Gu{\dh}nason, J{\'o}n},
4 booktitle={Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)},
5 pages={14305--14312},
6 year={2024}
7}