patrickvonplaten commited on
Commit
ef7575a
1 Parent(s): 8d0b881

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -5
README.md CHANGED
@@ -18,55 +18,76 @@ model-index:
18
  dataset:
19
  name: Common Voice ta
20
  type: common_voice
21
- args: {lang_id}
22
  metrics:
23
  - name: Test WER
24
  type: wer
25
- value: 0.7071799915694815
26
  ---
27
  # Wav2Vec2-Large-XLSR-53-tamil
 
28
  Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) in Tamil using the [Common Voice](https://huggingface.co/datasets/common_voice)
 
29
  When using this model, make sure that your speech input is sampled at 16kHz.
 
30
  ## Usage
31
  The model can be used directly (without a language model) as follows:
 
32
  ```python
33
  import torch
34
  import torchaudio
35
  from datasets import load_dataset
36
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
37
- test_dataset = load_dataset("common_voice", "tr", split="test[:2%]").
 
 
38
  processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
39
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
 
40
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
 
41
  # Preprocessing the datasets.
42
  # We need to read the aduio files as arrays
 
43
  def speech_file_to_array_fn(batch):
44
  speech_array, sampling_rate = torchaudio.load(batch["path"])
45
  batch["speech"] = resampler(speech_array).squeeze().numpy()
46
  return batch
 
47
  test_dataset = test_dataset.map(speech_file_to_array_fn)
48
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
 
49
  with torch.no_grad():
50
  logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
 
51
  predicted_ids = torch.argmax(logits, dim=-1)
52
  print("Prediction:", processor.batch_decode(predicted_ids))
53
  print("Reference:", test_dataset["sentence"][:2])
54
  ```
 
55
  ## Evaluation
 
56
  The model can be evaluated as follows on the {language} test data of Common Voice.
 
57
  ```python
58
  import torch
59
  import torchaudio
60
  from datasets import load_dataset, load_metric
61
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
62
  import re
 
63
  test_dataset = load_dataset("common_voice", "tr", split="test")
 
64
  wer = load_metric("wer")
 
65
  processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
66
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
 
67
  model.to("cuda")
68
  chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]'
 
69
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
 
70
  # Preprocessing the datasets.
71
  # We need to read the aduio files as arrays
72
  def speech_file_to_array_fn(batch):
@@ -74,17 +95,21 @@ def speech_file_to_array_fn(batch):
74
  speech_array, sampling_rate = torchaudio.load(batch["path"])
75
  batch["speech"] = resampler(speech_array).squeeze().numpy()
76
  return batch
 
77
  test_dataset = test_dataset.map(speech_file_to_array_fn)
 
78
  # Preprocessing the datasets.
79
  # We need to read the aduio files as arrays
80
  def evaluate(batch):
81
  inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
82
  with torch.no_grad():
83
  logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
84
- pred_ids = torch.argmax(logits, dim=-1)
85
  batch["pred_strings"] = processor.batch_decode(pred_ids)
86
  return batch
 
87
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
88
  print(wer.compute(predictions=result["predicted"], references=result["target"]))
89
  ```
90
- **Test Result**: 0.7071799915694815
 
18
  dataset:
19
  name: Common Voice ta
20
  type: common_voice
21
+ args: ta
22
  metrics:
23
  - name: Test WER
24
  type: wer
25
+ value: 70.72
26
  ---
27
  # Wav2Vec2-Large-XLSR-53-tamil
28
+
29
  Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) in Tamil using the [Common Voice](https://huggingface.co/datasets/common_voice)
30
+
31
  When using this model, make sure that your speech input is sampled at 16kHz.
32
+
33
  ## Usage
34
  The model can be used directly (without a language model) as follows:
35
+
36
  ```python
37
  import torch
38
  import torchaudio
39
  from datasets import load_dataset
40
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
41
+
42
+ test_dataset = load_dataset("common_voice", "tr", split="test[:2%]")
43
+
44
  processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
45
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
46
+
47
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
48
+
49
  # Preprocessing the datasets.
50
  # We need to read the aduio files as arrays
51
+
52
  def speech_file_to_array_fn(batch):
53
  speech_array, sampling_rate = torchaudio.load(batch["path"])
54
  batch["speech"] = resampler(speech_array).squeeze().numpy()
55
  return batch
56
+
57
  test_dataset = test_dataset.map(speech_file_to_array_fn)
58
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
59
+
60
  with torch.no_grad():
61
  logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
62
+
63
  predicted_ids = torch.argmax(logits, dim=-1)
64
  print("Prediction:", processor.batch_decode(predicted_ids))
65
  print("Reference:", test_dataset["sentence"][:2])
66
  ```
67
+
68
  ## Evaluation
69
+
70
  The model can be evaluated as follows on the {language} test data of Common Voice.
71
+
72
  ```python
73
  import torch
74
  import torchaudio
75
  from datasets import load_dataset, load_metric
76
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
77
  import re
78
+
79
  test_dataset = load_dataset("common_voice", "tr", split="test")
80
+
81
  wer = load_metric("wer")
82
+
83
  processor = Wav2Vec2Processor.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
84
  model = Wav2Vec2ForCTC.from_pretrained("Rajaram1996/wav2vec2-large-xlsr-tamil")
85
+
86
  model.to("cuda")
87
  chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"\“]'
88
+
89
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
90
+
91
  # Preprocessing the datasets.
92
  # We need to read the aduio files as arrays
93
  def speech_file_to_array_fn(batch):
95
  speech_array, sampling_rate = torchaudio.load(batch["path"])
96
  batch["speech"] = resampler(speech_array).squeeze().numpy()
97
  return batch
98
+
99
  test_dataset = test_dataset.map(speech_file_to_array_fn)
100
+
101
  # Preprocessing the datasets.
102
  # We need to read the aduio files as arrays
103
  def evaluate(batch):
104
  inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
105
  with torch.no_grad():
106
  logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
107
+ pred_ids = torch.argmax(logits, dim=-1)
108
  batch["pred_strings"] = processor.batch_decode(pred_ids)
109
  return batch
110
+
111
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
112
  print(wer.compute(predictions=result["predicted"], references=result["target"]))
113
  ```
114
+
115
+ **Test Result**: 70.72 %