Views
No views yet
1import torch
2from transformers import WhisperForConditionalGeneration, WhisperProcessor
3
4#Load the processor and model.
5MODEL_NAME="carlosdanielhernandezmena/whisper-small-faroese-5k-steps-100h"
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("carlosdanielhernandezmena/ravnursson_asr",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@misc{mena2023whispersmallfaroese,
2 title={Acoustic Model in Faroese: whisper-small-faroese-5k-steps-100h.},
3 author={Hernandez Mena, Carlos Daniel},
4 url={https://huggingface.co/carlosdanielhernandezmena/whisper-small-faroese-5k-steps-100h},
5 year={2023}
6}