patrickvonplaten commited on
Commit
369853e
1 Parent(s): 45a852f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +23 -23
README.md CHANGED
@@ -11,7 +11,7 @@ tags:
11
  - xlsr-fine-tuning-week
12
  license: apache-2.0
13
  model-index:
14
- - name: (Anton Lozhkov) Russian XLSR Wav2Vec2 Large 53
15
  results:
16
  - task:
17
  name: Speech Recognition
@@ -51,15 +51,15 @@ resampler = torchaudio.transforms.Resample(48_000, 16_000)
51
  # Preprocessing the datasets.
52
  # We need to read the aduio files as arrays
53
  def speech_file_to_array_fn(batch):
54
- speech_array, sampling_rate = torchaudio.load(batch["path"])
55
- batch["speech"] = resampler(speech_array).squeeze().numpy()
56
- return batch
57
 
58
  test_dataset = test_dataset.map(speech_file_to_array_fn)
59
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
60
 
61
  with torch.no_grad():
62
- logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
63
 
64
  predicted_ids = torch.argmax(logits, dim=-1)
65
 
@@ -90,36 +90,36 @@ model.to("cuda")
90
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
91
 
92
  def clean_sentence(sent):
93
- sent = sent.lower()
94
- # replace non-alphanumeric characters with space ("какой-то, вот" -> "какой то вот")
95
- sent = "".join(ch if ch.isalnum() else " " for ch in sent)
96
- # remove repeated spaces
97
- sent = " ".join(sent.split())
98
- # these letters are considered equivalent in written Russian
99
- sent = sent.replace('ё', 'е')
100
- return sent
101
 
102
  # Preprocessing the datasets.
103
  # We need to read the aduio files as arrays
104
  def speech_file_to_array_fn(batch):
105
- batch["sentence"] = clean_sentence(batch["sentence"])
106
- speech_array, sampling_rate = torchaudio.load(batch["path"])
107
- batch["speech"] = resampler(speech_array).squeeze().numpy()
108
- return batch
109
 
110
  test_dataset = test_dataset.map(speech_file_to_array_fn)
111
 
112
  # Preprocessing the datasets.
113
  # We need to read the aduio files as arrays
114
  def evaluate(batch):
115
- inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
116
 
117
- with torch.no_grad():
118
- logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
119
 
120
- pred_ids = torch.argmax(logits, dim=-1)
121
- batch["pred_strings"] = processor.batch_decode(pred_ids)
122
- return batch
123
 
124
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
125
 
 
11
  - xlsr-fine-tuning-week
12
  license: apache-2.0
13
  model-index:
14
+ - name: Russian XLSR Wav2Vec2 Large 53 by Anton Lozhkov
15
  results:
16
  - task:
17
  name: Speech Recognition
 
51
  # Preprocessing the datasets.
52
  # We need to read the aduio files as arrays
53
  def speech_file_to_array_fn(batch):
54
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
55
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
56
+ \treturn batch
57
 
58
  test_dataset = test_dataset.map(speech_file_to_array_fn)
59
  inputs = processor(test_dataset["speech"][:2], sampling_rate=16_000, return_tensors="pt", padding=True)
60
 
61
  with torch.no_grad():
62
+ \tlogits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
63
 
64
  predicted_ids = torch.argmax(logits, dim=-1)
65
 
 
90
  resampler = torchaudio.transforms.Resample(48_000, 16_000)
91
 
92
  def clean_sentence(sent):
93
+ \tsent = sent.lower()
94
+ \t# replace non-alphanumeric characters with space ("какой-то, вот" -> "какой то вот")
95
+ \tsent = "".join(ch if ch.isalnum() else " " for ch in sent)
96
+ \t# remove repeated spaces
97
+ \tsent = " ".join(sent.split())
98
+ \t# these letters are considered equivalent in written Russian
99
+ \tsent = sent.replace('ё', 'е')
100
+ \treturn sent
101
 
102
  # Preprocessing the datasets.
103
  # We need to read the aduio files as arrays
104
  def speech_file_to_array_fn(batch):
105
+ \tbatch["sentence"] = clean_sentence(batch["sentence"])
106
+ \tspeech_array, sampling_rate = torchaudio.load(batch["path"])
107
+ \tbatch["speech"] = resampler(speech_array).squeeze().numpy()
108
+ \treturn batch
109
 
110
  test_dataset = test_dataset.map(speech_file_to_array_fn)
111
 
112
  # Preprocessing the datasets.
113
  # We need to read the aduio files as arrays
114
  def evaluate(batch):
115
+ \tinputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
116
 
117
+ \twith torch.no_grad():
118
+ \t\tlogits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
119
 
120
+ \tpred_ids = torch.argmax(logits, dim=-1)
121
+ \tbatch["pred_strings"] = processor.batch_decode(pred_ids)
122
+ \treturn batch
123
 
124
  result = test_dataset.map(evaluate, batched=True, batch_size=8)
125