初始化项目,由ModelHub XC社区提供模型
Model: gigant/romanian-wav2vec2 Source: Original Platform
This commit is contained in:
28
.gitattributes
vendored
Normal file
28
.gitattributes
vendored
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
model.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
checkpoint-*/
|
||||||
277
README.md
Normal file
277
README.md
Normal file
@@ -0,0 +1,277 @@
|
|||||||
|
---
|
||||||
|
language:
|
||||||
|
- ro
|
||||||
|
license: apache-2.0
|
||||||
|
tags:
|
||||||
|
- automatic-speech-recognition
|
||||||
|
- hf-asr-leaderboard
|
||||||
|
- robust-speech-event
|
||||||
|
datasets:
|
||||||
|
- mozilla-foundation/common_voice_8_0
|
||||||
|
- gigant/romanian_speech_synthesis_0_8_1
|
||||||
|
base_model: facebook/wav2vec2-xls-r-300m
|
||||||
|
model-index:
|
||||||
|
- name: wav2vec2-ro-300m_01
|
||||||
|
results:
|
||||||
|
- task:
|
||||||
|
type: automatic-speech-recognition
|
||||||
|
name: Automatic Speech Recognition
|
||||||
|
dataset:
|
||||||
|
name: Robust Speech Event
|
||||||
|
type: speech-recognition-community-v2/dev_data
|
||||||
|
args: ro
|
||||||
|
metrics:
|
||||||
|
- type: wer
|
||||||
|
value: 46.99
|
||||||
|
name: Dev WER (without LM)
|
||||||
|
- type: cer
|
||||||
|
value: 16.04
|
||||||
|
name: Dev CER (without LM)
|
||||||
|
- type: wer
|
||||||
|
value: 38.63
|
||||||
|
name: Dev WER (with LM)
|
||||||
|
- type: cer
|
||||||
|
value: 14.52
|
||||||
|
name: Dev CER (with LM)
|
||||||
|
- task:
|
||||||
|
type: automatic-speech-recognition
|
||||||
|
name: Automatic Speech Recognition
|
||||||
|
dataset:
|
||||||
|
name: Common Voice
|
||||||
|
type: mozilla-foundation/common_voice_8_0
|
||||||
|
args: ro
|
||||||
|
metrics:
|
||||||
|
- type: wer
|
||||||
|
value: 11.73
|
||||||
|
name: Test WER (without LM)
|
||||||
|
- type: cer
|
||||||
|
value: 2.93
|
||||||
|
name: Test CER (without LM)
|
||||||
|
- type: wer
|
||||||
|
value: 7.31
|
||||||
|
name: Test WER (with LM)
|
||||||
|
- type: cer
|
||||||
|
value: 2.17
|
||||||
|
name: Test CER (with LM)
|
||||||
|
- task:
|
||||||
|
type: automatic-speech-recognition
|
||||||
|
name: Automatic Speech Recognition
|
||||||
|
dataset:
|
||||||
|
name: Robust Speech Event - Test Data
|
||||||
|
type: speech-recognition-community-v2/eval_data
|
||||||
|
args: ro
|
||||||
|
metrics:
|
||||||
|
- type: wer
|
||||||
|
value: 43.23
|
||||||
|
name: Test WER
|
||||||
|
---
|
||||||
|
|
||||||
|
You can test this model online with the [**Space for Romanian Speech Recognition**](https://huggingface.co/spaces/gigant/romanian-speech-recognition)
|
||||||
|
|
||||||
|
The model ranked **TOP-1** on Romanian Speech Recognition during HuggingFace's Robust Speech Challenge :
|
||||||
|
|
||||||
|
* [**The 🤗 Speech Bench**](https://huggingface.co/spaces/huggingface/hf-speech-bench)
|
||||||
|
|
||||||
|
* [**Speech Challenge Leaderboard**](https://huggingface.co/spaces/speech-recognition-community-v2/FinalLeaderboard)
|
||||||
|
|
||||||
|
# Romanian Wav2Vec2
|
||||||
|
|
||||||
|
This model is a fine-tuned version of [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) on the [Common Voice 8.0 - Romanian subset](https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0) dataset, with extra training data from [Romanian Speech Synthesis](https://huggingface.co/datasets/gigant/romanian_speech_synthesis_0_8_1) dataset.
|
||||||
|
|
||||||
|
Without the 5-gram Language Model optimization, it achieves the following results on the evaluation set (Common Voice 8.0, Romanian subset, test split):
|
||||||
|
- Loss: 0.1553
|
||||||
|
- Wer: 0.1174
|
||||||
|
- Cer: 0.0294
|
||||||
|
|
||||||
|
## Model description
|
||||||
|
|
||||||
|
The architecture is based on [facebook/wav2vec2-xls-r-300m](https://huggingface.co/facebook/wav2vec2-xls-r-300m) with a speech recognition CTC head and an added 5-gram language model (using [pyctcdecode](https://github.com/kensho-technologies/pyctcdecode) and [kenlm](https://github.com/kpu/kenlm)) trained on the [Romanian Corpora Parliament](gigant/ro_corpora_parliament_processed) dataset. Those libraries are needed in order for the language model-boosted decoder to work.
|
||||||
|
|
||||||
|
## Intended uses & limitations
|
||||||
|
|
||||||
|
The model is made for speech recognition in Romanian from audio clips sampled at **16kHz**. The predicted text is lowercased and does not contain any punctuation.
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
Make sure you have installed the correct dependencies for the language model-boosted version to work. You can just run this command to install the `kenlm` and `pyctcdecode` libraries :
|
||||||
|
|
||||||
|
```pip install https://github.com/kpu/kenlm/archive/master.zip pyctcdecode```
|
||||||
|
|
||||||
|
|
||||||
|
With the framework `transformers` you can load the model with the following code :
|
||||||
|
|
||||||
|
```
|
||||||
|
from transformers import AutoProcessor, AutoModelForCTC
|
||||||
|
|
||||||
|
processor = AutoProcessor.from_pretrained("gigant/romanian-wav2vec2")
|
||||||
|
|
||||||
|
model = AutoModelForCTC.from_pretrained("gigant/romanian-wav2vec2")
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, if you want to test the model, you can load the automatic speech recognition pipeline from `transformers` with :
|
||||||
|
|
||||||
|
```
|
||||||
|
from transformers import pipeline
|
||||||
|
|
||||||
|
asr = pipeline("automatic-speech-recognition", model="gigant/romanian-wav2vec2")
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Example use with the `datasets` library
|
||||||
|
|
||||||
|
First, you need to load your data
|
||||||
|
|
||||||
|
We will use the [Romanian Speech Synthesis](https://huggingface.co/datasets/gigant/romanian_speech_synthesis_0_8_1) dataset in this example.
|
||||||
|
|
||||||
|
```
|
||||||
|
from datasets import load_dataset
|
||||||
|
|
||||||
|
dataset = load_dataset("gigant/romanian_speech_synthesis_0_8_1")
|
||||||
|
```
|
||||||
|
|
||||||
|
You can listen to the samples with the `IPython.display` library :
|
||||||
|
|
||||||
|
```
|
||||||
|
from IPython.display import Audio
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
sample = dataset["train"][i]
|
||||||
|
Audio(sample["audio"]["array"], rate = sample["audio"]["sampling_rate"])
|
||||||
|
```
|
||||||
|
|
||||||
|
The model is trained to work with audio sampled at 16kHz, so if the sampling rate of the audio in the dataset is different, we will have to resample it.
|
||||||
|
|
||||||
|
In the example, the audio is sampled at 48kHz. We can see this by checking `dataset["train"][0]["audio"]["sampling_rate"]`
|
||||||
|
|
||||||
|
The following code resample the audio using the `torchaudio` library :
|
||||||
|
|
||||||
|
```
|
||||||
|
import torchaudio
|
||||||
|
import torch
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
audio = sample["audio"]["array"]
|
||||||
|
rate = sample["audio"]["sampling_rate"]
|
||||||
|
resampler = torchaudio.transforms.Resample(rate, 16_000)
|
||||||
|
audio_16 = resampler(torch.Tensor(audio)).numpy()
|
||||||
|
```
|
||||||
|
|
||||||
|
To listen to the resampled sample :
|
||||||
|
|
||||||
|
```
|
||||||
|
Audio(audio_16, rate=16000)
|
||||||
|
```
|
||||||
|
|
||||||
|
Know you can get the model prediction by running
|
||||||
|
|
||||||
|
```
|
||||||
|
predicted_text = asr(audio_16)
|
||||||
|
ground_truth = dataset["train"][i]["sentence"]
|
||||||
|
|
||||||
|
print(f"Predicted text : {predicted_text}")
|
||||||
|
print(f"Ground truth : {ground_truth}")
|
||||||
|
```
|
||||||
|
|
||||||
|
## Training and evaluation data
|
||||||
|
|
||||||
|
Training data :
|
||||||
|
- [Common Voice 8.0 - Romanian subset](https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0) : train + validation + other splits
|
||||||
|
- [Romanian Speech Synthesis](https://huggingface.co/datasets/gigant/romanian_speech_synthesis_0_8_1) : train + test splits
|
||||||
|
|
||||||
|
Evaluation data :
|
||||||
|
- [Common Voice 8.0 - Romanian subset](https://huggingface.co/datasets/mozilla-foundation/common_voice_8_0) : test split
|
||||||
|
|
||||||
|
## Training procedure
|
||||||
|
|
||||||
|
### Training hyperparameters
|
||||||
|
|
||||||
|
The following hyperparameters were used during training:
|
||||||
|
- learning_rate: 0.003
|
||||||
|
- train_batch_size: 16
|
||||||
|
- eval_batch_size: 8
|
||||||
|
- seed: 42
|
||||||
|
- gradient_accumulation_steps: 3
|
||||||
|
- total_train_batch_size: 48
|
||||||
|
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
|
||||||
|
- lr_scheduler_type: linear
|
||||||
|
- lr_scheduler_warmup_steps: 500
|
||||||
|
- num_epochs: 50.0
|
||||||
|
- mixed_precision_training: Native AMP
|
||||||
|
|
||||||
|
### Training results
|
||||||
|
|
||||||
|
| Training Loss | Epoch | Step | Validation Loss | Wer | Cer |
|
||||||
|
|:-------------:|:-----:|:-----:|:---------------:|:------:|:------:|
|
||||||
|
| 2.9272 | 0.78 | 500 | 0.7603 | 0.7734 | 0.2355 |
|
||||||
|
| 0.6157 | 1.55 | 1000 | 0.4003 | 0.4866 | 0.1247 |
|
||||||
|
| 0.4452 | 2.33 | 1500 | 0.2960 | 0.3689 | 0.0910 |
|
||||||
|
| 0.3631 | 3.11 | 2000 | 0.2580 | 0.3205 | 0.0796 |
|
||||||
|
| 0.3153 | 3.88 | 2500 | 0.2465 | 0.2977 | 0.0747 |
|
||||||
|
| 0.2795 | 4.66 | 3000 | 0.2274 | 0.2789 | 0.0694 |
|
||||||
|
| 0.2615 | 5.43 | 3500 | 0.2277 | 0.2685 | 0.0675 |
|
||||||
|
| 0.2389 | 6.21 | 4000 | 0.2135 | 0.2518 | 0.0627 |
|
||||||
|
| 0.2229 | 6.99 | 4500 | 0.2054 | 0.2449 | 0.0614 |
|
||||||
|
| 0.2067 | 7.76 | 5000 | 0.2096 | 0.2378 | 0.0597 |
|
||||||
|
| 0.1977 | 8.54 | 5500 | 0.2042 | 0.2387 | 0.0600 |
|
||||||
|
| 0.1896 | 9.32 | 6000 | 0.2110 | 0.2383 | 0.0595 |
|
||||||
|
| 0.1801 | 10.09 | 6500 | 0.1909 | 0.2165 | 0.0548 |
|
||||||
|
| 0.174 | 10.87 | 7000 | 0.1883 | 0.2206 | 0.0559 |
|
||||||
|
| 0.1685 | 11.65 | 7500 | 0.1848 | 0.2097 | 0.0528 |
|
||||||
|
| 0.1591 | 12.42 | 8000 | 0.1851 | 0.2039 | 0.0514 |
|
||||||
|
| 0.1537 | 13.2 | 8500 | 0.1881 | 0.2065 | 0.0518 |
|
||||||
|
| 0.1504 | 13.97 | 9000 | 0.1840 | 0.1972 | 0.0499 |
|
||||||
|
| 0.145 | 14.75 | 9500 | 0.1845 | 0.2029 | 0.0517 |
|
||||||
|
| 0.1417 | 15.53 | 10000 | 0.1884 | 0.2003 | 0.0507 |
|
||||||
|
| 0.1364 | 16.3 | 10500 | 0.2010 | 0.2037 | 0.0517 |
|
||||||
|
| 0.1331 | 17.08 | 11000 | 0.1838 | 0.1923 | 0.0483 |
|
||||||
|
| 0.129 | 17.86 | 11500 | 0.1818 | 0.1922 | 0.0489 |
|
||||||
|
| 0.1198 | 18.63 | 12000 | 0.1760 | 0.1861 | 0.0465 |
|
||||||
|
| 0.1203 | 19.41 | 12500 | 0.1686 | 0.1839 | 0.0465 |
|
||||||
|
| 0.1225 | 20.19 | 13000 | 0.1828 | 0.1920 | 0.0479 |
|
||||||
|
| 0.1145 | 20.96 | 13500 | 0.1673 | 0.1784 | 0.0446 |
|
||||||
|
| 0.1053 | 21.74 | 14000 | 0.1802 | 0.1810 | 0.0456 |
|
||||||
|
| 0.1071 | 22.51 | 14500 | 0.1769 | 0.1775 | 0.0444 |
|
||||||
|
| 0.1053 | 23.29 | 15000 | 0.1920 | 0.1783 | 0.0457 |
|
||||||
|
| 0.1024 | 24.07 | 15500 | 0.1904 | 0.1775 | 0.0446 |
|
||||||
|
| 0.0987 | 24.84 | 16000 | 0.1793 | 0.1762 | 0.0446 |
|
||||||
|
| 0.0949 | 25.62 | 16500 | 0.1801 | 0.1766 | 0.0443 |
|
||||||
|
| 0.0942 | 26.4 | 17000 | 0.1731 | 0.1659 | 0.0423 |
|
||||||
|
| 0.0906 | 27.17 | 17500 | 0.1776 | 0.1698 | 0.0424 |
|
||||||
|
| 0.0861 | 27.95 | 18000 | 0.1716 | 0.1600 | 0.0406 |
|
||||||
|
| 0.0851 | 28.73 | 18500 | 0.1662 | 0.1630 | 0.0410 |
|
||||||
|
| 0.0844 | 29.5 | 19000 | 0.1671 | 0.1572 | 0.0393 |
|
||||||
|
| 0.0792 | 30.28 | 19500 | 0.1768 | 0.1599 | 0.0407 |
|
||||||
|
| 0.0798 | 31.06 | 20000 | 0.1732 | 0.1558 | 0.0394 |
|
||||||
|
| 0.0779 | 31.83 | 20500 | 0.1694 | 0.1544 | 0.0388 |
|
||||||
|
| 0.0718 | 32.61 | 21000 | 0.1709 | 0.1578 | 0.0399 |
|
||||||
|
| 0.0732 | 33.38 | 21500 | 0.1697 | 0.1523 | 0.0391 |
|
||||||
|
| 0.0708 | 34.16 | 22000 | 0.1616 | 0.1474 | 0.0375 |
|
||||||
|
| 0.0678 | 34.94 | 22500 | 0.1698 | 0.1474 | 0.0375 |
|
||||||
|
| 0.0642 | 35.71 | 23000 | 0.1681 | 0.1459 | 0.0369 |
|
||||||
|
| 0.0661 | 36.49 | 23500 | 0.1612 | 0.1411 | 0.0357 |
|
||||||
|
| 0.0629 | 37.27 | 24000 | 0.1662 | 0.1414 | 0.0355 |
|
||||||
|
| 0.0587 | 38.04 | 24500 | 0.1659 | 0.1408 | 0.0351 |
|
||||||
|
| 0.0581 | 38.82 | 25000 | 0.1612 | 0.1382 | 0.0352 |
|
||||||
|
| 0.0556 | 39.6 | 25500 | 0.1647 | 0.1376 | 0.0345 |
|
||||||
|
| 0.0543 | 40.37 | 26000 | 0.1658 | 0.1335 | 0.0337 |
|
||||||
|
| 0.052 | 41.15 | 26500 | 0.1716 | 0.1369 | 0.0343 |
|
||||||
|
| 0.0513 | 41.92 | 27000 | 0.1600 | 0.1317 | 0.0330 |
|
||||||
|
| 0.0491 | 42.7 | 27500 | 0.1671 | 0.1311 | 0.0328 |
|
||||||
|
| 0.0463 | 43.48 | 28000 | 0.1613 | 0.1289 | 0.0324 |
|
||||||
|
| 0.0468 | 44.25 | 28500 | 0.1599 | 0.1260 | 0.0315 |
|
||||||
|
| 0.0435 | 45.03 | 29000 | 0.1556 | 0.1232 | 0.0308 |
|
||||||
|
| 0.043 | 45.81 | 29500 | 0.1588 | 0.1240 | 0.0309 |
|
||||||
|
| 0.0421 | 46.58 | 30000 | 0.1567 | 0.1217 | 0.0308 |
|
||||||
|
| 0.04 | 47.36 | 30500 | 0.1533 | 0.1198 | 0.0302 |
|
||||||
|
| 0.0389 | 48.14 | 31000 | 0.1582 | 0.1185 | 0.0297 |
|
||||||
|
| 0.0387 | 48.91 | 31500 | 0.1576 | 0.1187 | 0.0297 |
|
||||||
|
| 0.0376 | 49.69 | 32000 | 0.1560 | 0.1182 | 0.0295 |
|
||||||
|
|
||||||
|
|
||||||
|
### Framework versions
|
||||||
|
|
||||||
|
- Transformers 4.16.2
|
||||||
|
- Pytorch 1.10.0+cu111
|
||||||
|
- Tokenizers 0.11.0
|
||||||
|
- pyctcdecode 0.3.0
|
||||||
|
- kenlm
|
||||||
1
added_tokens.json
Normal file
1
added_tokens.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"<s>": 34, "</s>": 35}
|
||||||
15
all_results.json
Normal file
15
all_results.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"epoch": 50.0,
|
||||||
|
"eval_cer": 0.029360946316590746,
|
||||||
|
"eval_loss": 0.15534016489982605,
|
||||||
|
"eval_runtime": 138.9476,
|
||||||
|
"eval_samples": 3843,
|
||||||
|
"eval_samples_per_second": 27.658,
|
||||||
|
"eval_steps_per_second": 3.462,
|
||||||
|
"eval_wer": 0.11739302551552884,
|
||||||
|
"train_loss": 0.17004985039278586,
|
||||||
|
"train_runtime": 77839.5185,
|
||||||
|
"train_samples": 30943,
|
||||||
|
"train_samples_per_second": 19.876,
|
||||||
|
"train_steps_per_second": 0.414
|
||||||
|
}
|
||||||
1
alphabet.json
Normal file
1
alphabet.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"labels": [" ", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "\u00e2", "\u00ee", "\u0103", "\u0219", "\u021b", "\u2047", "", "<s>", "</s>"], "is_bpe": false}
|
||||||
107
config.json
Normal file
107
config.json
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
{
|
||||||
|
"_name_or_path": "facebook/wav2vec2-xls-r-300m",
|
||||||
|
"activation_dropout": 0.0,
|
||||||
|
"adapter_kernel_size": 3,
|
||||||
|
"adapter_stride": 2,
|
||||||
|
"add_adapter": false,
|
||||||
|
"apply_spec_augment": true,
|
||||||
|
"architectures": [
|
||||||
|
"Wav2Vec2ForCTC"
|
||||||
|
],
|
||||||
|
"attention_dropout": 0.0,
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"classifier_proj_size": 256,
|
||||||
|
"codevector_dim": 768,
|
||||||
|
"contrastive_logits_temperature": 0.1,
|
||||||
|
"conv_bias": true,
|
||||||
|
"conv_dim": [
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512
|
||||||
|
],
|
||||||
|
"conv_kernel": [
|
||||||
|
10,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
2,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"conv_stride": [
|
||||||
|
5,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2,
|
||||||
|
2
|
||||||
|
],
|
||||||
|
"ctc_loss_reduction": "mean",
|
||||||
|
"ctc_zero_infinity": false,
|
||||||
|
"diversity_loss_weight": 0.1,
|
||||||
|
"do_stable_layer_norm": true,
|
||||||
|
"eos_token_id": 2,
|
||||||
|
"feat_extract_activation": "gelu",
|
||||||
|
"feat_extract_dropout": 0.0,
|
||||||
|
"feat_extract_norm": "layer",
|
||||||
|
"feat_proj_dropout": 0.0,
|
||||||
|
"feat_quantizer_dropout": 0.0,
|
||||||
|
"final_dropout": 0.0,
|
||||||
|
"hidden_act": "gelu",
|
||||||
|
"hidden_dropout": 0.0,
|
||||||
|
"hidden_size": 1024,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"intermediate_size": 4096,
|
||||||
|
"layer_norm_eps": 1e-05,
|
||||||
|
"layerdrop": 0.1,
|
||||||
|
"mask_feature_length": 10,
|
||||||
|
"mask_feature_min_masks": 0,
|
||||||
|
"mask_feature_prob": 0.0,
|
||||||
|
"mask_time_length": 10,
|
||||||
|
"mask_time_min_masks": 2,
|
||||||
|
"mask_time_prob": 0.05,
|
||||||
|
"model_type": "wav2vec2",
|
||||||
|
"num_adapter_layers": 3,
|
||||||
|
"num_attention_heads": 16,
|
||||||
|
"num_codevector_groups": 2,
|
||||||
|
"num_codevectors_per_group": 320,
|
||||||
|
"num_conv_pos_embedding_groups": 16,
|
||||||
|
"num_conv_pos_embeddings": 128,
|
||||||
|
"num_feat_extract_layers": 7,
|
||||||
|
"num_hidden_layers": 24,
|
||||||
|
"num_negatives": 100,
|
||||||
|
"output_hidden_size": 1024,
|
||||||
|
"pad_token_id": 33,
|
||||||
|
"proj_codevector_dim": 768,
|
||||||
|
"tdnn_dilation": [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"tdnn_dim": [
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
512,
|
||||||
|
1500
|
||||||
|
],
|
||||||
|
"tdnn_kernel": [
|
||||||
|
5,
|
||||||
|
3,
|
||||||
|
3,
|
||||||
|
1,
|
||||||
|
1
|
||||||
|
],
|
||||||
|
"torch_dtype": "float32",
|
||||||
|
"transformers_version": "4.16.0.dev0",
|
||||||
|
"use_weighted_layer_sum": false,
|
||||||
|
"vocab_size": 36,
|
||||||
|
"xvector_output_dim": 512
|
||||||
|
}
|
||||||
140
eval.py
Normal file
140
eval.py
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import re
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
from datasets import Audio, Dataset, load_dataset, load_metric
|
||||||
|
|
||||||
|
from transformers import AutoFeatureExtractor, pipeline
|
||||||
|
|
||||||
|
|
||||||
|
def log_results(result: Dataset, args: Dict[str, str]):
|
||||||
|
"""DO NOT CHANGE. This function computes and logs the result metrics."""
|
||||||
|
|
||||||
|
log_outputs = args.log_outputs
|
||||||
|
dataset_id = "_".join(args.dataset.split("/") + [args.config, args.split])
|
||||||
|
|
||||||
|
# load metric
|
||||||
|
wer = load_metric("wer")
|
||||||
|
cer = load_metric("cer")
|
||||||
|
|
||||||
|
# compute metrics
|
||||||
|
wer_result = wer.compute(references=result["target"], predictions=result["prediction"])
|
||||||
|
cer_result = cer.compute(references=result["target"], predictions=result["prediction"])
|
||||||
|
|
||||||
|
# print & log results
|
||||||
|
result_str = f"WER: {wer_result}\n" f"CER: {cer_result}"
|
||||||
|
print(result_str)
|
||||||
|
|
||||||
|
with open(f"{dataset_id}_eval_results.txt", "w") as f:
|
||||||
|
f.write(result_str)
|
||||||
|
|
||||||
|
# log all results in text file. Possibly interesting for analysis
|
||||||
|
if log_outputs is not None:
|
||||||
|
pred_file = f"log_{dataset_id}_predictions.txt"
|
||||||
|
target_file = f"log_{dataset_id}_targets.txt"
|
||||||
|
|
||||||
|
with open(pred_file, "w") as p, open(target_file, "w") as t:
|
||||||
|
|
||||||
|
# mapping function to write output
|
||||||
|
def write_to_file(batch, i):
|
||||||
|
p.write(f"{i}" + "\n")
|
||||||
|
p.write(batch["prediction"] + "\n")
|
||||||
|
t.write(f"{i}" + "\n")
|
||||||
|
t.write(batch["target"] + "\n")
|
||||||
|
|
||||||
|
result.map(write_to_file, with_indices=True)
|
||||||
|
|
||||||
|
|
||||||
|
def normalize_text(text: str) -> str:
|
||||||
|
"""DO ADAPT FOR YOUR USE CASE. this function normalizes the target text."""
|
||||||
|
|
||||||
|
chars_to_ignore_regex = '[,?.!\-\;\:"“%‘”<EFBFBD>—’…–„]' # noqa: W605 IMPORTANT: this should correspond to the chars that were ignored during training
|
||||||
|
|
||||||
|
text = re.sub(chars_to_ignore_regex, "", text.lower())
|
||||||
|
|
||||||
|
# In addition, we can normalize the target text, e.g. removing new lines characters etc...
|
||||||
|
# note that order is important here!
|
||||||
|
token_sequences_to_ignore = ["\n\n", "\n", " ", " "]
|
||||||
|
|
||||||
|
for t in token_sequences_to_ignore:
|
||||||
|
text = " ".join(text.split(t))
|
||||||
|
|
||||||
|
#Replace some characters that are not in the Romanian alphabet but are found in the dataset
|
||||||
|
text = re.sub('[á]', 'a', text)
|
||||||
|
text = re.sub('[é]', 'e', text)
|
||||||
|
text = re.sub('[í]', 'i', text)
|
||||||
|
text = re.sub('[ò]', 'o', text)
|
||||||
|
text = re.sub('[ü]', 'u', text)
|
||||||
|
text = re.sub('[ć]', 'c', text)
|
||||||
|
text = re.sub('[đ]', 'd', text)
|
||||||
|
text = re.sub('[č]', 'c', text)
|
||||||
|
text = re.sub('[š]', 's', text)
|
||||||
|
text = re.sub('[ş]', 'ș', text) #Replace the s-cedilla that is sometimes (wrongly) used instead of the s-comma
|
||||||
|
text = re.sub('[ţ]', 'ț', text) #Replace the t-cedilla that is sometimes (wrongly) used instead of the t-comma
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def main(args):
|
||||||
|
# load dataset
|
||||||
|
dataset = load_dataset(args.dataset, args.config, split=args.split, use_auth_token=True)
|
||||||
|
|
||||||
|
# for testing: only process the first two examples as a test
|
||||||
|
# dataset = dataset.select(range(10))
|
||||||
|
|
||||||
|
# load processor
|
||||||
|
feature_extractor = AutoFeatureExtractor.from_pretrained(args.model_id)
|
||||||
|
sampling_rate = feature_extractor.sampling_rate
|
||||||
|
|
||||||
|
# resample audio
|
||||||
|
dataset = dataset.cast_column("audio", Audio(sampling_rate=sampling_rate))
|
||||||
|
|
||||||
|
# load eval pipeline
|
||||||
|
asr = pipeline("automatic-speech-recognition", model=args.model_id)
|
||||||
|
|
||||||
|
# map function to decode audio
|
||||||
|
def map_to_pred(batch):
|
||||||
|
prediction = asr(
|
||||||
|
batch["audio"]["array"], chunk_length_s=args.chunk_length_s, stride_length_s=args.stride_length_s
|
||||||
|
)
|
||||||
|
|
||||||
|
batch["prediction"] = prediction["text"]
|
||||||
|
batch["target"] = normalize_text(batch["sentence"])
|
||||||
|
return batch
|
||||||
|
|
||||||
|
# run inference on all examples
|
||||||
|
result = dataset.map(map_to_pred, remove_columns=dataset.column_names)
|
||||||
|
|
||||||
|
# compute and log_results
|
||||||
|
# do not change function below
|
||||||
|
log_results(result, args)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"--model_id", type=str, required=True, help="Model identifier. Should be loadable with 🤗 Transformers"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--dataset",
|
||||||
|
type=str,
|
||||||
|
required=True,
|
||||||
|
help="Dataset name to evaluate the `model_id`. Should be loadable with 🤗 Datasets",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--config", type=str, required=True, help="Config of the dataset. *E.g.* `'en'` for Common Voice"
|
||||||
|
)
|
||||||
|
parser.add_argument("--split", type=str, required=True, help="Split of the dataset. *E.g.* `'test'`")
|
||||||
|
parser.add_argument(
|
||||||
|
"--chunk_length_s", type=float, default=None, help="Chunk length in seconds. Defaults to 5 seconds."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--stride_length_s", type=float, default=None, help="Stride of the audio chunks. Defaults to 1 second."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--log_outputs", action="store_true", help="If defined, write outputs to log file for analysis."
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(args)
|
||||||
7
eval.sh
Normal file
7
eval.sh
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
python eval.py \
|
||||||
|
--model_id="gigant/romanian-wav2vec2" \
|
||||||
|
--dataset="speech-recognition-community-v2/dev_data" \
|
||||||
|
--config="ro" \
|
||||||
|
--split="validation" \
|
||||||
|
--chunk_length_s 10 \
|
||||||
|
--stride_length_s 1 \
|
||||||
10
eval_results.json
Normal file
10
eval_results.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"epoch": 50.0,
|
||||||
|
"eval_cer": 0.029360946316590746,
|
||||||
|
"eval_loss": 0.15534016489982605,
|
||||||
|
"eval_runtime": 138.9476,
|
||||||
|
"eval_samples": 3843,
|
||||||
|
"eval_samples_per_second": 27.658,
|
||||||
|
"eval_steps_per_second": 3.462,
|
||||||
|
"eval_wer": 0.11739302551552884
|
||||||
|
}
|
||||||
3
language_model/5gram.bin
Normal file
3
language_model/5gram.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:b03301f34e511db37a2b00ea1bd61eb4db755478bea45c74498f9f97d3762dff
|
||||||
|
size 491769893
|
||||||
1
language_model/attrs.json
Normal file
1
language_model/attrs.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"alpha": 0.5, "beta": 1.5, "unk_score_offset": -10.0, "score_boundary": true}
|
||||||
87809
language_model/unigrams.txt
Normal file
87809
language_model/unigrams.txt
Normal file
File diff suppressed because it is too large
Load Diff
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:a42ddf6318dfb62d1375887f03cf8d725d7c91e257f8b86487384d4e8d98a800
|
||||||
|
size 1261955032
|
||||||
10
preprocessor_config.json
Normal file
10
preprocessor_config.json
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"do_normalize": true,
|
||||||
|
"feature_extractor_type": "Wav2Vec2FeatureExtractor",
|
||||||
|
"feature_size": 1,
|
||||||
|
"padding_side": "right",
|
||||||
|
"padding_value": 0,
|
||||||
|
"processor_class": "Wav2Vec2ProcessorWithLM",
|
||||||
|
"return_attention_mask": true,
|
||||||
|
"sampling_rate": 16000
|
||||||
|
}
|
||||||
3
pytorch_model.bin
Normal file
3
pytorch_model.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:d0b801c7a4fa42854484db39077806d1d0997f8bb7dab06721d2d7f5a6e90ccc
|
||||||
|
size 1262071281
|
||||||
1
special_tokens_map.json
Normal file
1
special_tokens_map.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "[UNK]", "pad_token": "[PAD]", "additional_special_tokens": [{"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "<s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, {"content": "</s>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}]}
|
||||||
1
tokenizer_config.json
Normal file
1
tokenizer_config.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"unk_token": "[UNK]", "bos_token": "<s>", "eos_token": "</s>", "pad_token": "[PAD]", "do_lower_case": false, "word_delimiter_token": "|", "special_tokens_map_file": null, "tokenizer_file": null, "name_or_path": "gigant/wav2vec2-ro-300m_01", "tokenizer_class": "Wav2Vec2CTCTokenizer", "processor_class": "Wav2Vec2ProcessorWithLM"}
|
||||||
8
train_results.json
Normal file
8
train_results.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"epoch": 50.0,
|
||||||
|
"train_loss": 0.17004985039278586,
|
||||||
|
"train_runtime": 77839.5185,
|
||||||
|
"train_samples": 30943,
|
||||||
|
"train_samples_per_second": 19.876,
|
||||||
|
"train_steps_per_second": 0.414
|
||||||
|
}
|
||||||
1049
trainer_state.json
Normal file
1049
trainer_state.json
Normal file
File diff suppressed because it is too large
Load Diff
3
training_args.bin
Normal file
3
training_args.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:cd7ffa627b29ea27b82a7931cc22a9fb4a091533e719e9390368c2eaf451a89f
|
||||||
|
size 3055
|
||||||
1
vocab.json
Normal file
1
vocab.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, "â": 27, "î": 28, "ă": 29, "ș": 30, "ț": 31, "|": 0, "[UNK]": 32, "[PAD]": 33}
|
||||||
Reference in New Issue
Block a user