gorkemgoknar commited on
Commit
854cbad
1 Parent(s): ec6a450

Update README.md

Browse files

Added description

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