gchhablani commited on
Commit
e9e2db3
1 Parent(s): 7a26e16

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +96 -0
README.md ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: or
3
+ datasets:
4
+ - common_voice
5
+ metrics:
6
+ - wer
7
+ tags:
8
+ - audio
9
+ - automatic-speech-recognition
10
+ - speech
11
+ - xlsr-fine-tuning-week
12
+ license: apache-2.0
13
+ model-index:
14
+ - name: XLSR Wav2Vec2 Large 53 Odia by Gunjan Chhablani
15
+ results:
16
+ - task:
17
+ name: Speech Recognition
18
+ type: automatic-speech-recognition
19
+ dataset:
20
+ name: Common Voice or
21
+ type: common_voice
22
+ args: or
23
+ metrics:
24
+ - name: Test WER
25
+ type: wer
26
+ value: 52.64
27
+ ---
28
+ # Wav2Vec2-Large-XLSR-53-Odia
29
+ Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Odia using the [Common Voice](https://huggingface.co/datasets/common_voice).
30
+ When using this model, make sure that your speech input is sampled at 16kHz.
31
+
32
+ ## Usage
33
+ The model can be used directly (without a language model) as follows:
34
+ ```python
35
+ import torch
36
+ import torchaudio
37
+ from datasets import load_dataset
38
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
39
+ test_dataset = load_dataset("common_voice", "or", split="test[:2%]")
40
+
41
+ processor = Wav2Vec2Processor.from_pretrained("gchhablani/wav2vec2-large-xlsr-or")
42
+ model = Wav2Vec2ForCTC.from_pretrained("gchhablani/wav2vec2-large-xlsr-or")
43
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
44
+ # Preprocessing the datasets.
45
+ # We need to read the aduio files as arrays
46
+ def speech_file_to_array_fn(batch):
47
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
48
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
49
+ return batch
50
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
51
+ inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
52
+ with torch.no_grad():
53
+ logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
54
+ predicted_ids = torch.argmax(logits, dim=-1)
55
+ print("Prediction:", processor.batch_decode(predicted_ids))
56
+ print("Reference:", test_dataset["sentence"][:2])
57
+ ```
58
+ ## Evaluation
59
+ The model can be evaluated as follows on the Odia test data of Common Voice.
60
+ ```python
61
+ import torch
62
+ import torchaudio
63
+ from datasets import load_dataset, load_metric
64
+ from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
65
+ import re
66
+ test_dataset = load_dataset("common_voice", "or", split="test")
67
+ wer = load_metric("wer")
68
+ processor = Wav2Vec2Processor.from_pretrained("gchhablani/wav2vec2-large-xlsr-or")
69
+ model = Wav2Vec2ForCTC.from_pretrained("gchhablani/wav2vec2-large-xlsr-or")
70
+ model.to("cuda")
71
+ chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\–\…\'\_\’\।\|]'
72
+ resampler = torchaudio.transforms.Resample(48_000, 16_000)
73
+ # Preprocessing the datasets.
74
+ # We need to read the aduio files as arrays
75
+ def speech_file_to_array_fn(batch):
76
+ batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
77
+ speech_array, sampling_rate = torchaudio.load(batch["path"])
78
+ batch["speech"] = resampler(speech_array).squeeze().numpy()
79
+ return batch
80
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
81
+ # Preprocessing the datasets.
82
+ # We need to read the aduio files as arrays
83
+ def evaluate(batch):
84
+ inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
85
+ with torch.no_grad():
86
+ logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
87
+ pred_ids = torch.argmax(logits, dim=-1)
88
+ batch["pred_strings"] = processor.batch_decode(pred_ids)
89
+ return batch
90
+ result = test_dataset.map(evaluate, batched=True, batch_size=8)
91
+ print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["sentence"])))
92
+ ```
93
+ **Test Result**: 52.64 %
94
+
95
+ ## Training
96
+ The Common Voice `train` and `validation` datasets were used for training.The colab notebook used can be found [here](https://colab.research.google.com/drive/1s8DrwgB5y4Z7xXIrPXo1rQA5_1OZ8WD5?usp=sharing).