gagan3012 commited on
Commit
9b0c538
1 Parent(s): 4341bdc

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +27 -23
README.md CHANGED
@@ -30,7 +30,7 @@ model-index:
30
 
31
  # Wav2Vec2-Large-XLSR-53-khmer
32
 
33
- Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Khmer using the [Common Voice](https://huggingface.co/datasets/common_voice), and [OpenSLR Kh](http://www.openslr.org/43/).
34
 
35
  When using this model, make sure that your speech input is sampled at 16kHz.
36
 
@@ -44,12 +44,12 @@ import torchaudio
44
  from datasets import load_dataset
45
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
46
 
47
- !wget https://www.openslr.org/resources/43/km_kh_male.zip
48
  !unzip km_kh_male.zip
49
  !ls km_kh_male
50
 
51
  colnames=['path','sentence']
52
- df = pd.read_csv('/content/km_kh_male/line_index.tsv',sep='\\\\\\\\\\\\\\\\t',header=None,names = colnames)
53
  df['path'] = '/content/km_kh_male/wavs/'+df['path'] +'.wav'
54
 
55
  train, test = train_test_split(df, test_size=0.1)
@@ -66,15 +66,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
66
  # Preprocessing the datasets.
67
  # We need to read the aduio files as arrays
68
  def speech_file_to_array_fn(batch):
69
- \\\\\\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
70
- \\\\\\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
71
- \\\\\\\\treturn batch
72
 
73
  test_dataset = test_dataset.map(speech_file_to_array_fn)
74
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
75
 
76
  with torch.no_grad():
77
- \\\\\\\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
78
 
79
  predicted_ids = torch.argmax(logits, dim=-1)
80
 
@@ -103,13 +103,17 @@ from sklearn.model_selection import train_test_split
103
  import pandas as pd
104
  from datasets import load_dataset
105
 
106
- #!wget https://www.openslr.org/resources/43/ne_np_female.zip
107
- #!unzip ne_np_female.zip
108
- #!ls ne_np_female
109
- !mkdir cer
110
- !wget -O cer/cer.py https://huggingface.co/ctl/wav2vec2-large-xlsr-cantonese/raw/main/cer.py
111
 
 
 
 
112
 
 
 
 
113
 
114
  test_dataset = load_dataset('csv', data_files='/content/km_kh_male/line_index_test.csv',split = 'train')
115
  wer = load_metric("wer")
@@ -120,30 +124,30 @@ processor = Wav2Vec2Processor.from_pretrained("gagan3012/wav2vec2-xlsr-khmer")
120
  model = Wav2Vec2ForCTC.from_pretrained("gagan3012/wav2vec2-xlsr-khmer")
121
  model.to("cuda")
122
 
123
- chars_to_ignore_regex = '[\\,\\?\\.\\!\\-\\;\\:\\"\\“]'
124
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
125
 
126
  # Preprocessing the datasets.
127
  # We need to read the aduio files as arrays
128
  def speech_file_to_array_fn(batch):
129
- \tbatch["text"] = re.sub(chars_to_ignore_regex, '', batch["text"]).lower()
130
- \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
131
- \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
132
- \treturn batch
133
 
134
  test_dataset = test_dataset.map(speech_file_to_array_fn)
135
 
136
  # Preprocessing the datasets.
137
  # We need to read the aduio files as arrays
138
  def evaluate(batch):
139
- \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
140
 
141
- \twith torch.no_grad():
142
- \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
143
 
144
- \tpred_ids = torch.argmax(logits, dim=-1)
145
- \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
146
- \treturn batch
147
 
148
  cer = load_metric("cer")
149
 
30
 
31
  # Wav2Vec2-Large-XLSR-53-khmer
32
 
33
+ Fine-tuned [facebook/wav2vec2-large-xlsr-53](https://huggingface.co/facebook/wav2vec2-large-xlsr-53) on Khmer using the [Common Voice](https://huggingface.co/datasets/common_voice), and [OpenSLR Kh](http://www.openslr.org/42/).
34
 
35
  When using this model, make sure that your speech input is sampled at 16kHz.
36
 
44
  from datasets import load_dataset
45
  from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
46
 
47
+ !wget https://www.openslr.org/resources/42/km_kh_male.zip
48
  !unzip km_kh_male.zip
49
  !ls km_kh_male
50
 
51
  colnames=['path','sentence']
52
+ df = pd.read_csv('/content/km_kh_male/line_index.tsv',sep='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\t',header=None,names = colnames)
53
  df['path'] = '/content/km_kh_male/wavs/'+df['path'] +'.wav'
54
 
55
  train, test = train_test_split(df, test_size=0.1)
66
  # Preprocessing the datasets.
67
  # We need to read the aduio files as arrays
68
  def speech_file_to_array_fn(batch):
69
+ \\\\\\\\\\\\\\\\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
70
+ \\\\\\\\\\\\\\\\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
71
+ \\\\\\\\\\\\\\\\treturn batch
72
 
73
  test_dataset = test_dataset.map(speech_file_to_array_fn)
74
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
75
 
76
  with torch.no_grad():
77
+ \\\\\\\\\\\\\\\\tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
78
 
79
  predicted_ids = torch.argmax(logits, dim=-1)
80
 
103
  import pandas as pd
104
  from datasets import load_dataset
105
 
106
+ !wget https://www.openslr.org/resources/42/km_kh_male.zip
107
+ !unzip km_kh_male.zip
108
+ !ls km_kh_male
 
 
109
 
110
+ colnames=['path','sentence']
111
+ df = pd.read_csv('/content/km_kh_male/line_index.tsv',sep='\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\t',header=None,names = colnames)
112
+ df['path'] = '/content/km_kh_male/wavs/'+df['path'] +'.wav'
113
 
114
+ train, test = train_test_split(df, test_size=0.1)
115
+
116
+ test.to_csv('/content/km_kh_male/line_index_test.csv')
117
 
118
  test_dataset = load_dataset('csv', data_files='/content/km_kh_male/line_index_test.csv',split = 'train')
119
  wer = load_metric("wer")
124
  model = Wav2Vec2ForCTC.from_pretrained("gagan3012/wav2vec2-xlsr-khmer")
125
  model.to("cuda")
126
 
127
+ chars_to_ignore_regex = '[\\\\,\\\\?\\\\.\\\\!\\\\-\\\\;\\\\:\\\\"\\\\“]'
128
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
129
 
130
  # Preprocessing the datasets.
131
  # We need to read the aduio files as arrays
132
  def speech_file_to_array_fn(batch):
133
+ \\tbatch["text"] = re.sub(chars_to_ignore_regex, '', batch["text"]).lower()
134
+ \\tspeech_array, sampling_rate = torchaudio.load(batch["path"])
135
+ \\tbatch["speech"] = resampler(speech_array).squeeze().numpy()
136
+ \\treturn batch
137
 
138
  test_dataset = test_dataset.map(speech_file_to_array_fn)
139
 
140
  # Preprocessing the datasets.
141
  # We need to read the aduio files as arrays
142
  def evaluate(batch):
143
+ \\tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
144
 
145
+ \\twith torch.no_grad():
146
+ \\t\\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
147
 
148
+ \\tpred_ids = torch.argmax(logits, dim=-1)
149
+ \\tbatch["pred_strings"] = processor.batch_decode(pred_ids)
150
+ \\treturn batch
151
 
152
  cer = load_metric("cer")
153