Views
No views yet
| Step | Training Loss | Validation Loss | Wer |
|---|---|---|---|
| 1500 | 2.854200 | 0.642243 | 0.543964 |
| 3000 | 0.599200 | 0.468138 | 0.429549 |
| 4500 | 0.468300 | 0.433436 | 0.405644 |
| 6000 | 0.427000 | 0.384873 | 0.344150 |
| 7500 | 0.377000 | 0.374003 | 0.323892 |
| 9000 | 0.337000 | 0.363674 | 0.306189 |
| 10500 | 0.302400 | 0.349884 | 0 .283908 |
| 12000 | 0.264100 | 0.344104 | 0.277120 |
| 13500 | 0 .254000 | 0.341820 | 0.271316 |
| 15000 | 0.208400 | 0.326502 | 0.260695 |
| 16500 | 0.203500 | 0.326209 | 0.250313 |
| 18000 | 0.159800 | 0.323539 | 0.239851 |
| 19500 | 0.158200 | 0.310694 | 0.230028 |
| 21000 | 0.132800 | 0.338318 | 0.229283 |
| 22500 | 0.112800 | 0.336765 | 0.224145 |
| 24000 | 0.103600 | 0.350208 | 0.227073 |
| 25500 | 0.091400 | 0.353609 | 0.221589 |
| 27000 | 0.084400 | 0.367826 | 0.212565 |
1import librosa
2import warnings
3from transformers import AutoProcessor, AutoModelForCTC
4from datasets import Dataset, DatasetDict
5from datasets import load_metric
6
7wer_metric = load_metric("wer")
8
9wolof = pd.read_csv('Test.csv') # wolof contains the columns of file , and transcription
10wolof = DatasetDict({'test': Dataset.from_pandas(wolof)})
11
12chars_to_ignore_regex = '[\"\?\.\!\-\;\:\(\)\,]'
13
14def remove_special_characters(batch):
15 batch["transcription"] = re.sub(chars_to_ignore_regex, '', batch["transcription"]).lower() + " "
16 return batch
17
18
19wolof = wolof.map(remove_special_characters)
20
21processor = AutoProcessor.from_pretrained("abdouaziiz/wav2vec2-xls-r-300m-wolof-lm")
22model = AutoModelForCTC.from_pretrained("abdouaziiz/wav2vec2-xls-r-300m-wolof-lm")
23
24warnings.filterwarnings("ignore")
25def speech_file_to_array_fn(batch):
26 speech_array, sampling_rate = librosa.load(batch["file"], sr = 16000)
27 batch["speech"] = speech_array.astype('float16')
28 batch["sampling_rate"] = sampling_rate
29 batch["target_text"] = batch["transcription"]
30 return batch
31
32wolof = wolof.map(speech_file_to_array_fn, remove_columns=wolof.column_names["test"], num_proc=1)
33
34def map_to_result(batch):
35 model.to("cuda")
36 input_values = processor(
37 batch["speech"],
38 sampling_rate=batch["sampling_rate"],
39 return_tensors="pt"
40 ).input_values.to("cuda")
41
42 with torch.no_grad():
43 logits = model(input_values).logits
44 pred_ids = torch.argmax(logits, dim=-1)
45 batch["pred_str"] = processor.batch_decode(pred_ids)[0]
46
47 return batch
48
49 results = wolof["test"].map(map_to_result)
50
51 print("Test WER: {:.3f}".format(wer_metric.compute(predictions=results["pred_str"], references=results["transcription"])))
52