Merge branch 'main' of https://huggingface.co/KBLab/wav2vec2-large-voxrex-swedish into main
Browse files- README.md +65 -0
- chart_1.svg +0 -0
- tokenizer_config.json +1 -1
- vocab.json +1 -1
README.md
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: sv-SE
|
3 |
+
datasets:
|
4 |
+
- common_voice
|
5 |
+
- NST Swedish ASR Database
|
6 |
+
- P4
|
7 |
+
metrics:
|
8 |
+
- wer
|
9 |
+
tags:
|
10 |
+
- audio
|
11 |
+
- automatic-speech-recognition
|
12 |
+
- speech
|
13 |
+
license: cc0
|
14 |
+
model-index:
|
15 |
+
- name: Wav2vec 2.0 large VoxRex Swedish
|
16 |
+
results:
|
17 |
+
- task:
|
18 |
+
name: Speech Recognition
|
19 |
+
type: automatic-speech-recognition
|
20 |
+
dataset:
|
21 |
+
name: Common Voice
|
22 |
+
type: common_voice
|
23 |
+
args: sv-SE
|
24 |
+
metrics:
|
25 |
+
- name: Test WER
|
26 |
+
type: wer
|
27 |
+
value: 9.914
|
28 |
+
---
|
29 |
+
# Wav2vec 2.0 large VoxRex Swedish
|
30 |
+
|
31 |
+
Finetuned version of KBs [VoxRex large](https://huggingface.co/KBLab/wav2vec2-large-voxrex) model using Swedish radio broadcasts, NST and Common Voice data. Evalutation without a language model gives the following: WER for NST + Common Voice test set (2% of total sentences) is **3.617%**. WER for Common Voice test set is **9.914%** directly and **7.77%** with a 4-gram language model.
|
32 |
+
|
33 |
+
When using this model, make sure that your speech input is sampled at 16kHz.
|
34 |
+
|
35 |
+
## Training
|
36 |
+
This model has additionally pretrained on 3500h of a mix of Swedish local radio broadcasts, audio books and other audio sources. It has been fine-tuned for 120000 updates on NST + CommonVoice and then for an additional 20000 updates on CommonVoice only. The additional fine-tuning on CommonVoice hurts performance on the NST+CommonVoice test set somewhat and, unsurprisingly, improves it on the CommonVoice test set. It seems to perform generally better though [citation needed].
|
37 |
+
|
38 |
+
![WER during training](chart_1.svg "WER")
|
39 |
+
|
40 |
+
## Usage
|
41 |
+
The model can be used directly (without a language model) as follows:
|
42 |
+
```python
|
43 |
+
import torch
|
44 |
+
import torchaudio
|
45 |
+
from datasets import load_dataset
|
46 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
47 |
+
test_dataset = load_dataset("common_voice", "sv-SE", split="test[:2%]").
|
48 |
+
processor = Wav2Vec2Processor.from_pretrained("KBLab/wav2vec2-large-voxrex-swedish")
|
49 |
+
model = Wav2Vec2ForCTC.from_pretrained("KBLab/wav2vec2-large-voxpopuli-sv-swedish")
|
50 |
+
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 |
+
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 |
+
with torch.no_grad():
|
60 |
+
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
|
61 |
+
predicted_ids = torch.argmax(logits, dim=-1)
|
62 |
+
print("Prediction:", processor.batch_decode(predicted_ids))
|
63 |
+
print("Reference:", test_dataset["sentence"][:2])
|
64 |
+
```
|
65 |
+
|
chart_1.svg
ADDED
|
tokenizer_config.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>", "pad_token": "<pad>", "do_lower_case":
|
|
|
1 |
+
{"unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>", "pad_token": "<pad>", "do_lower_case": true, "word_delimiter_token": "|", "tokenizer_class": "Wav2Vec2CTCTokenizer"}
|
vocab.json
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"<
|
|
|
1 |
+
{"<pad>": 0, "<s>": 1, "</s>": 2, "<unk>": 3, "|": 4, "T": 5, "E": 6, "A": 7, "N": 8, "R": 9, "S": 10, "I": 11, "L": 12, "D": 13, "O": 14, "M": 15, "K": 16, "G": 17, "U": 18, "V": 19, "F": 20, "H": 21, "Ä": 22, "Å": 23, "P": 24, "Ö": 25, "B": 26, "J": 27, "C": 28, "Y": 29, "X": 30, "W": 31, "Z": 32, "É": 33, "Q": 34, "8": 35, "2": 36, "5": 37, "9": 38, "1": 39, "6": 40, "7": 41, "3": 42, "4": 43, "0": 44, "'": 45}
|