patrickvonplaten
commited on
Commit
•
369853e
1
Parent(s):
45a852f
Update README.md
Browse files
README.md
CHANGED
@@ -11,7 +11,7 @@ tags:
|
|
11 |
- xlsr-fine-tuning-week
|
12 |
license: apache-2.0
|
13 |
model-index:
|
14 |
-
- name:
|
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 |
-
|
55 |
-
|
56 |
-
|
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 |
-
|
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 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
|
102 |
# Preprocessing the datasets.
|
103 |
# We need to read the aduio files as arrays
|
104 |
def speech_file_to_array_fn(batch):
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
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 |
-
|
116 |
|
117 |
-
|
118 |
-
|
119 |
|
120 |
-
|
121 |
-
|
122 |
-
|
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 |
|