初始化项目,由ModelHub XC社区提供模型
Model: Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 Source: Original Platform
This commit is contained in:
29
.gitattributes
vendored
Normal file
29
.gitattributes
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
*.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
|
||||||
|
*unigrams.txt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
model.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
264
README.md
Normal file
264
README.md
Normal file
@@ -0,0 +1,264 @@
|
|||||||
|
---
|
||||||
|
license: apache-2.0
|
||||||
|
language: fi
|
||||||
|
metrics:
|
||||||
|
- wer
|
||||||
|
- cer
|
||||||
|
tags:
|
||||||
|
- automatic-speech-recognition
|
||||||
|
- fi
|
||||||
|
- finnish
|
||||||
|
- generated_from_trainer
|
||||||
|
- hf-asr-leaderboard
|
||||||
|
- robust-speech-event
|
||||||
|
datasets:
|
||||||
|
- mozilla-foundation/common_voice_7_0
|
||||||
|
model-index:
|
||||||
|
- name: wav2vec2-xlsr-1b-finnish-lm-v2
|
||||||
|
results:
|
||||||
|
- task:
|
||||||
|
name: Automatic Speech Recognition
|
||||||
|
type: automatic-speech-recognition
|
||||||
|
dataset:
|
||||||
|
name: Common Voice 7
|
||||||
|
type: mozilla-foundation/common_voice_7_0
|
||||||
|
args: fi
|
||||||
|
metrics:
|
||||||
|
- name: Test WER
|
||||||
|
type: wer
|
||||||
|
value: 4.09
|
||||||
|
- name: Test CER
|
||||||
|
type: cer
|
||||||
|
value: 0.88
|
||||||
|
- task:
|
||||||
|
name: Automatic Speech Recognition
|
||||||
|
type: automatic-speech-recognition
|
||||||
|
dataset:
|
||||||
|
name: FLEURS ASR
|
||||||
|
type: google/fleurs
|
||||||
|
args: fi_fi
|
||||||
|
metrics:
|
||||||
|
- name: Test WER
|
||||||
|
type: wer
|
||||||
|
value: 12.11
|
||||||
|
- name: Test CER
|
||||||
|
type: cer
|
||||||
|
value: 5.65
|
||||||
|
---
|
||||||
|
|
||||||
|
# Wav2vec2-xls-r-1b for Finnish ASR
|
||||||
|
|
||||||
|
This acoustic model is a fine-tuned version of [facebook/wav2vec2-xls-r-1b](https://huggingface.co/facebook/wav2vec2-xls-r-1b) for Finnish ASR. The model has been fine-tuned with 275.6 hours of Finnish transcribed speech data. Wav2Vec2 XLS-R was introduced in
|
||||||
|
[this paper](https://arxiv.org/abs/2111.09296) and first released at [this page](https://github.com/pytorch/fairseq/tree/main/examples/wav2vec#wav2vec-20).
|
||||||
|
|
||||||
|
This repository also includes Finnish KenLM language model used in the decoding phase with the acoustic model.
|
||||||
|
|
||||||
|
**Note**: this model is exactly the same as the [aapot/wav2vec2-xlsr-1b-finnish-lm-v2](https://huggingface.co/aapot/wav2vec2-xlsr-1b-finnish-lm-v2) model so that model has just been copied/moved to this `Finnish-NLP` Hugging Face organization.
|
||||||
|
|
||||||
|
## Model description
|
||||||
|
|
||||||
|
Wav2Vec2 XLS-R is Facebook AI's large-scale multilingual pretrained model for speech. It is pretrained on 436k hours of unlabeled speech, including VoxPopuli, MLS, CommonVoice, BABEL, and VoxLingua107. It uses the wav2vec 2.0 objective, in 128 languages.
|
||||||
|
|
||||||
|
You can read more about the pretrained model from [this blog](https://ai.facebook.com/blog/xls-r-self-supervised-speech-processing-for-128-languages) and [this paper](https://arxiv.org/abs/2111.09296).
|
||||||
|
|
||||||
|
This model is fine-tuned version of the pretrained model (1 billion parameter variant) for Finnish ASR.
|
||||||
|
|
||||||
|
## Intended uses & limitations
|
||||||
|
|
||||||
|
You can use this model for Finnish ASR (speech-to-text) task.
|
||||||
|
|
||||||
|
### How to use
|
||||||
|
|
||||||
|
Check the [run-finnish-asr-models.ipynb](https://huggingface.co/Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2/blob/main/run-finnish-asr-models.ipynb) notebook in this repository for an detailed example on how to use this model.
|
||||||
|
|
||||||
|
### Limitations and bias
|
||||||
|
|
||||||
|
This model was fine-tuned with audio samples which maximum length was 20 seconds so this model most likely works the best for quite short audios of similar length. However, you can try this model with a lot longer audios too and see how it works. If you encounter out of memory errors with very long audio files you can use the audio chunking method introduced in [this blog post](https://huggingface.co/blog/asr-chunking).
|
||||||
|
|
||||||
|
A vast majority of the data used for fine-tuning was from the Finnish Parliament dataset so this model may not generalize so well to very different domains like common daily spoken Finnish with dialects etc. In addition, audios of the datasets tend to be adult male dominated so this model may not work as well for speeches of children and women, for example.
|
||||||
|
|
||||||
|
The Finnish KenLM language model used in the decoding phase has been trained with text data from the audio transcriptions and from a subset of Finnish Wikipedia. Thus, the decoder's language model may not generalize to very different language, for example to spoken daily language with dialects (because especially the Wikipedia contains mostly formal Finnish language). It may be beneficial to train your own KenLM language model for your domain language and use that in the decoding.
|
||||||
|
|
||||||
|
## Training data
|
||||||
|
|
||||||
|
This model was fine-tuned with 275.6 hours of Finnish transcribed speech data from following datasets:
|
||||||
|
|
||||||
|
| Dataset | Hours | % of total hours |
|
||||||
|
|:------------------------------------------------------------------------------------------------------------------------------ |:--------:|:----------------:|
|
||||||
|
| [Common Voice 7.0 Finnish train + evaluation + other splits](https://huggingface.co/datasets/mozilla-foundation/common_voice_7_0) | 9.70 h | 3.52 % |
|
||||||
|
| [Finnish parliament session 2](https://b2share.eudat.eu/records/4df422d631544ce682d6af1d4714b2d4) | 0.24 h | 0.09 % |
|
||||||
|
| [VoxPopuli Finnish](https://github.com/facebookresearch/voxpopuli) | 21.97 h | 7.97 % |
|
||||||
|
| [CSS10 Finnish](https://github.com/kyubyong/css10) | 10.32 h | 3.74 % |
|
||||||
|
| [Aalto Finnish Parliament ASR Corpus](http://urn.fi/urn:nbn:fi:lb-2021051903) | 228.00 h | 82.73 % |
|
||||||
|
| [Finnish Broadcast Corpus](http://urn.fi/urn:nbn:fi:lb-2016042502) | 5.37 h | 1.95 % |
|
||||||
|
|
||||||
|
Datasets were filtered to include maximum length of 20 seconds long audio samples.
|
||||||
|
|
||||||
|
## Training procedure
|
||||||
|
|
||||||
|
This model was trained during [Robust Speech Challenge Event](https://discuss.huggingface.co/t/open-to-the-community-robust-speech-recognition-challenge/13614) organized by Hugging Face. Training was done on a Tesla V100 GPU, sponsored by OVHcloud.
|
||||||
|
|
||||||
|
Training script was provided by Hugging Face and it is available [here](https://github.com/huggingface/transformers/blob/main/examples/research_projects/robust-speech-event/run_speech_recognition_ctc_bnb.py). We only modified its data loading for our custom datasets.
|
||||||
|
|
||||||
|
For the KenLM language model training, we followed the [blog post tutorial](https://huggingface.co/blog/wav2vec2-with-ngram) provided by Hugging Face. Training data for the 5-gram KenLM were text transcriptions of the audio training data and 100k random samples of cleaned [Finnish Wikipedia](https://huggingface.co/datasets/wikipedia) (August 2021) dataset.
|
||||||
|
|
||||||
|
### Training hyperparameters
|
||||||
|
|
||||||
|
The following hyperparameters were used during training:
|
||||||
|
- learning_rate: 5e-05
|
||||||
|
- train_batch_size: 32
|
||||||
|
- eval_batch_size: 8
|
||||||
|
- seed: 42
|
||||||
|
- optimizer: [8-bit Adam](https://github.com/facebookresearch/bitsandbytes) with betas=(0.9,0.999) and epsilon=1e-08
|
||||||
|
- lr_scheduler_type: linear
|
||||||
|
- lr_scheduler_warmup_steps: 500
|
||||||
|
- num_epochs: 10
|
||||||
|
- mixed_precision_training: Native AMP
|
||||||
|
|
||||||
|
The pretrained `facebook/wav2vec2-xls-r-1b` model was initialized with following hyperparameters:
|
||||||
|
- attention_dropout: 0.094
|
||||||
|
- hidden_dropout: 0.047
|
||||||
|
- feat_proj_dropout: 0.04
|
||||||
|
- mask_time_prob: 0.082
|
||||||
|
- layerdrop: 0.041
|
||||||
|
- activation_dropout: 0.055
|
||||||
|
- ctc_loss_reduction: "mean"
|
||||||
|
|
||||||
|
### Training results
|
||||||
|
|
||||||
|
| Training Loss | Epoch | Step | Validation Loss | Wer |
|
||||||
|
|:-------------:|:-----:|:-----:|:---------------:|:------:|
|
||||||
|
| 0.7778 | 0.17 | 500 | 0.2851 | 0.3572 |
|
||||||
|
| 0.5506 | 0.34 | 1000 | 0.1595 | 0.2130 |
|
||||||
|
| 0.6569 | 0.5 | 1500 | 0.1458 | 0.2046 |
|
||||||
|
| 0.5997 | 0.67 | 2000 | 0.1374 | 0.1975 |
|
||||||
|
| 0.542 | 0.84 | 2500 | 0.1390 | 0.1956 |
|
||||||
|
| 0.4815 | 1.01 | 3000 | 0.1266 | 0.1813 |
|
||||||
|
| 0.6982 | 1.17 | 3500 | 0.1441 | 0.1965 |
|
||||||
|
| 0.4522 | 1.34 | 4000 | 0.1232 | 0.1822 |
|
||||||
|
| 0.4655 | 1.51 | 4500 | 0.1209 | 0.1702 |
|
||||||
|
| 0.4069 | 1.68 | 5000 | 0.1149 | 0.1688 |
|
||||||
|
| 0.4226 | 1.84 | 5500 | 0.1121 | 0.1560 |
|
||||||
|
| 0.3993 | 2.01 | 6000 | 0.1091 | 0.1557 |
|
||||||
|
| 0.406 | 2.18 | 6500 | 0.1115 | 0.1553 |
|
||||||
|
| 0.4098 | 2.35 | 7000 | 0.1144 | 0.1560 |
|
||||||
|
| 0.3995 | 2.51 | 7500 | 0.1028 | 0.1476 |
|
||||||
|
| 0.4101 | 2.68 | 8000 | 0.1129 | 0.1511 |
|
||||||
|
| 0.3636 | 2.85 | 8500 | 0.1025 | 0.1517 |
|
||||||
|
| 0.3534 | 3.02 | 9000 | 0.1068 | 0.1480 |
|
||||||
|
| 0.3836 | 3.18 | 9500 | 0.1072 | 0.1459 |
|
||||||
|
| 0.3531 | 3.35 | 10000 | 0.0928 | 0.1367 |
|
||||||
|
| 0.3649 | 3.52 | 10500 | 0.1042 | 0.1426 |
|
||||||
|
| 0.3645 | 3.69 | 11000 | 0.0979 | 0.1433 |
|
||||||
|
| 0.3685 | 3.85 | 11500 | 0.0947 | 0.1346 |
|
||||||
|
| 0.3325 | 4.02 | 12000 | 0.0991 | 0.1352 |
|
||||||
|
| 0.3497 | 4.19 | 12500 | 0.0919 | 0.1358 |
|
||||||
|
| 0.3303 | 4.36 | 13000 | 0.0888 | 0.1272 |
|
||||||
|
| 0.3323 | 4.52 | 13500 | 0.0888 | 0.1277 |
|
||||||
|
| 0.3452 | 4.69 | 14000 | 0.0894 | 0.1279 |
|
||||||
|
| 0.337 | 4.86 | 14500 | 0.0917 | 0.1289 |
|
||||||
|
| 0.3114 | 5.03 | 15000 | 0.0942 | 0.1313 |
|
||||||
|
| 0.3099 | 5.19 | 15500 | 0.0902 | 0.1239 |
|
||||||
|
| 0.3079 | 5.36 | 16000 | 0.0871 | 0.1256 |
|
||||||
|
| 0.3293 | 5.53 | 16500 | 0.0861 | 0.1263 |
|
||||||
|
| 0.3123 | 5.7 | 17000 | 0.0876 | 0.1203 |
|
||||||
|
| 0.3093 | 5.86 | 17500 | 0.0848 | 0.1226 |
|
||||||
|
| 0.2903 | 6.03 | 18000 | 0.0914 | 0.1221 |
|
||||||
|
| 0.297 | 6.2 | 18500 | 0.0841 | 0.1185 |
|
||||||
|
| 0.2797 | 6.37 | 19000 | 0.0858 | 0.1165 |
|
||||||
|
| 0.2878 | 6.53 | 19500 | 0.0874 | 0.1161 |
|
||||||
|
| 0.2974 | 6.7 | 20000 | 0.0835 | 0.1173 |
|
||||||
|
| 0.3051 | 6.87 | 20500 | 0.0835 | 0.1178 |
|
||||||
|
| 0.2941 | 7.04 | 21000 | 0.0852 | 0.1155 |
|
||||||
|
| 0.258 | 7.21 | 21500 | 0.0832 | 0.1132 |
|
||||||
|
| 0.2778 | 7.37 | 22000 | 0.0829 | 0.1110 |
|
||||||
|
| 0.2751 | 7.54 | 22500 | 0.0822 | 0.1069 |
|
||||||
|
| 0.2887 | 7.71 | 23000 | 0.0819 | 0.1103 |
|
||||||
|
| 0.2509 | 7.88 | 23500 | 0.0787 | 0.1055 |
|
||||||
|
| 0.2501 | 8.04 | 24000 | 0.0807 | 0.1076 |
|
||||||
|
| 0.2399 | 8.21 | 24500 | 0.0784 | 0.1052 |
|
||||||
|
| 0.2539 | 8.38 | 25000 | 0.0772 | 0.1075 |
|
||||||
|
| 0.248 | 8.55 | 25500 | 0.0772 | 0.1055 |
|
||||||
|
| 0.2689 | 8.71 | 26000 | 0.0763 | 0.1027 |
|
||||||
|
| 0.2855 | 8.88 | 26500 | 0.0756 | 0.1035 |
|
||||||
|
| 0.2421 | 9.05 | 27000 | 0.0771 | 0.0998 |
|
||||||
|
| 0.2497 | 9.22 | 27500 | 0.0756 | 0.0971 |
|
||||||
|
| 0.2367 | 9.38 | 28000 | 0.0741 | 0.0974 |
|
||||||
|
| 0.2473 | 9.55 | 28500 | 0.0739 | 0.0982 |
|
||||||
|
| 0.2396 | 9.72 | 29000 | 0.0756 | 0.0991 |
|
||||||
|
| 0.2602 | 9.89 | 29500 | 0.0737 | 0.0975 |
|
||||||
|
|
||||||
|
|
||||||
|
### Framework versions
|
||||||
|
|
||||||
|
- Transformers 4.17.0.dev0
|
||||||
|
- Pytorch 1.10.2+cu102
|
||||||
|
- Datasets 1.18.3
|
||||||
|
- Tokenizers 0.11.0
|
||||||
|
|
||||||
|
## Evaluation results
|
||||||
|
|
||||||
|
Evaluation was done with the [Common Voice 7.0 Finnish test split](https://huggingface.co/datasets/mozilla-foundation/common_voice_7_0), [Common Voice 9.0 Finnish test split](https://huggingface.co/datasets/mozilla-foundation/common_voice_9_0) and with the [FLEURS ASR Finnish test split](https://huggingface.co/datasets/google/fleurs).
|
||||||
|
|
||||||
|
This model's training data includes the training splits of Common Voice 7.0 but our newer `Finnish-NLP/wav2vec2-base-fi-voxpopuli-v2-finetuned` and `Finnish-NLP/wav2vec2-large-uralic-voxpopuli-v2-finnish` models include the Common Voice 9.0 so we ran tests for both Common Voice versions. Note: Common Voice doesn't seem to fully preserve the test split as fixed between the dataset versions so it is possible that some of the training examples of Common Voice 9.0 are in the test split of the Common Voice 7.0 and vice versa. Thus, Common Voice test result comparisons are not fully accurate between the models trained with different Common Voice versions but the comparison should still be meaningful enough.
|
||||||
|
|
||||||
|
### Common Voice 7.0 testing
|
||||||
|
|
||||||
|
To evaluate this model, run the `eval.py` script in this repository:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 eval.py --model_id Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 --dataset mozilla-foundation/common_voice_7_0 --config fi --split test
|
||||||
|
```
|
||||||
|
|
||||||
|
This model (the fift row of the table) achieves the following WER (Word Error Rate) and CER (Character Error Rate) results compared to our other models and their parameter counts:
|
||||||
|
|
||||||
|
| | Model parameters | WER (with LM) | WER (without LM) | CER (with LM) | CER (without LM) |
|
||||||
|
|-------------------------------------------------------|------------------|---------------|------------------|---------------|------------------|
|
||||||
|
|Finnish-NLP/wav2vec2-base-fi-voxpopuli-v2-finetuned | 95 million |5.85 |13.52 |1.35 |2.44 |
|
||||||
|
|Finnish-NLP/wav2vec2-large-uralic-voxpopuli-v2-finnish | 300 million |4.13 |**9.66** |0.90 |1.66 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-300m-finnish-lm | 300 million |8.16 |17.92 |1.97 |3.36 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm | 1000 million |5.65 |13.11 |1.20 |2.23 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 | 1000 million |**4.09** |9.73 |**0.88** |**1.65** |
|
||||||
|
|
||||||
|
### Common Voice 9.0 testing
|
||||||
|
|
||||||
|
To evaluate this model, run the `eval.py` script in this repository:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 eval.py --model_id Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 --dataset mozilla-foundation/common_voice_9_0 --config fi --split test
|
||||||
|
```
|
||||||
|
|
||||||
|
This model (the fift row of the table) achieves the following WER (Word Error Rate) and CER (Character Error Rate) results compared to our other models and their parameter counts:
|
||||||
|
|
||||||
|
| | Model parameters | WER (with LM) | WER (without LM) | CER (with LM) | CER (without LM) |
|
||||||
|
|-------------------------------------------------------|------------------|---------------|------------------|---------------|------------------|
|
||||||
|
|Finnish-NLP/wav2vec2-base-fi-voxpopuli-v2-finetuned | 95 million |5.93 |14.08 |1.40 |2.59 |
|
||||||
|
|Finnish-NLP/wav2vec2-large-uralic-voxpopuli-v2-finnish | 300 million |4.13 |9.83 |0.92 |1.71 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-300m-finnish-lm | 300 million |7.42 |16.45 |1.79 |3.07 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm | 1000 million |5.35 |13.00 |1.14 |2.20 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 | 1000 million |**3.72** |**8.96** |**0.80** |**1.52** |
|
||||||
|
|
||||||
|
### FLEURS ASR testing
|
||||||
|
|
||||||
|
To evaluate this model, run the `eval.py` script in this repository:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python3 eval.py --model_id Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 --dataset google/fleurs --config fi_fi --split test
|
||||||
|
```
|
||||||
|
|
||||||
|
This model (the fift row of the table) achieves the following WER (Word Error Rate) and CER (Character Error Rate) results compared to our other models and their parameter counts:
|
||||||
|
|
||||||
|
| | Model parameters | WER (with LM) | WER (without LM) | CER (with LM) | CER (without LM) |
|
||||||
|
|-------------------------------------------------------|------------------|---------------|------------------|---------------|------------------|
|
||||||
|
|Finnish-NLP/wav2vec2-base-fi-voxpopuli-v2-finetuned | 95 million |13.99 |17.16 |6.07 |6.61 |
|
||||||
|
|Finnish-NLP/wav2vec2-large-uralic-voxpopuli-v2-finnish | 300 million |12.44 |**14.63** |5.77 |6.22 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-300m-finnish-lm | 300 million |17.72 |23.30 |6.78 |7.67 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm | 1000 million |20.34 |16.67 |6.97 |6.35 |
|
||||||
|
|Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 | 1000 million |**12.11** |14.89 |**5.65** |**6.06** |
|
||||||
|
|
||||||
|
## Team Members
|
||||||
|
|
||||||
|
- Aapo Tanskanen, [Hugging Face profile](https://huggingface.co/aapot), [LinkedIn profile](https://www.linkedin.com/in/aapotanskanen/)
|
||||||
|
- Rasmus Toivanen, [Hugging Face profile](https://huggingface.co/RASMUS), [LinkedIn profile](https://www.linkedin.com/in/rasmustoivanen/)
|
||||||
|
|
||||||
|
Feel free to contact us for more details 🤗
|
||||||
1
added_tokens.json
Normal file
1
added_tokens.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"<s>": 33, "</s>": 34}
|
||||||
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", "\u00e4", "\u00e5", "\u00f6", "\u2047", "", "<s>", "</s>"], "is_bpe": false}
|
||||||
108
config.json
Normal file
108
config.json
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
{
|
||||||
|
"_name_or_path": "facebook/wav2vec2-xls-r-1b",
|
||||||
|
"activation_dropout": 0.055,
|
||||||
|
"adapter_kernel_size": 3,
|
||||||
|
"adapter_stride": 2,
|
||||||
|
"add_adapter": false,
|
||||||
|
"apply_spec_augment": true,
|
||||||
|
"architectures": [
|
||||||
|
"Wav2Vec2ForCTC"
|
||||||
|
],
|
||||||
|
"attention_dropout": 0.094,
|
||||||
|
"bos_token_id": 1,
|
||||||
|
"classifier_proj_size": 256,
|
||||||
|
"codevector_dim": 1024,
|
||||||
|
"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.04,
|
||||||
|
"feat_quantizer_dropout": 0.0,
|
||||||
|
"final_dropout": 0.0,
|
||||||
|
"gradient_checkpointing": false,
|
||||||
|
"hidden_act": "gelu",
|
||||||
|
"hidden_dropout": 0.047,
|
||||||
|
"hidden_size": 1280,
|
||||||
|
"initializer_range": 0.02,
|
||||||
|
"intermediate_size": 5120,
|
||||||
|
"layer_norm_eps": 1e-05,
|
||||||
|
"layerdrop": 0.041,
|
||||||
|
"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.082,
|
||||||
|
"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": 48,
|
||||||
|
"num_negatives": 100,
|
||||||
|
"output_hidden_size": 1280,
|
||||||
|
"pad_token_id": 32,
|
||||||
|
"proj_codevector_dim": 1024,
|
||||||
|
"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.17.0.dev0",
|
||||||
|
"use_weighted_layer_sum": false,
|
||||||
|
"vocab_size": 35,
|
||||||
|
"xvector_output_dim": 512
|
||||||
|
}
|
||||||
144
eval.py
Normal file
144
eval.py
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
import argparse
|
||||||
|
import re
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
import torch
|
||||||
|
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 = [",", "?", "¿", ".", "!", "¡", ";", ";", ":", '""', "%", '"', "<EFBFBD>", "ʿ", "·", "჻", "~", "՞",
|
||||||
|
"؟", "،", "।", "॥", "«", "»", "„", "“", "”", "「", "」", "‘", "’", "《", "》", "(", ")", "[", "]",
|
||||||
|
"{", "}", "=", "`", "_", "+", "<", ">", "…", "–", "°", "´", "ʾ", "‹", "›", "©", "®", "—", "→", "。",
|
||||||
|
"、", "﹂", "﹁", "‧", "~", "﹏", ",", "{", "}", "(", ")", "[", "]", "【", "】", "‥", "〽",
|
||||||
|
"『", "』", "〝", "〟", "⟨", "⟩", "〜", ":", "!", "?", "♪", "؛", "/", "\\", "º", "−", "^", "ʻ", "ˆ"] # noqa: W605 IMPORTANT: this should correspond to the chars that were ignored during training
|
||||||
|
|
||||||
|
chars_to_remove_regex = f"[{re.escape(''.join(CHARS_TO_IGNORE))}]"
|
||||||
|
|
||||||
|
text = re.sub(chars_to_remove_regex, "", text.lower())
|
||||||
|
text = re.sub("[-]", " ", text)
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
|
||||||
|
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
|
||||||
|
if args.device is None:
|
||||||
|
args.device = 0 if torch.cuda.is_available() else -1
|
||||||
|
asr = pipeline("automatic-speech-recognition", model=args.model_id, device=args.device)
|
||||||
|
|
||||||
|
# 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."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--device",
|
||||||
|
type=int,
|
||||||
|
default=None,
|
||||||
|
help="The device to run the pipeline on. -1 for CPU (default), 0 for the first GPU and so on.",
|
||||||
|
)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
main(args)
|
||||||
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}
|
||||||
3
language_model/kenlm_finnish.bin
Normal file
3
language_model/kenlm_finnish.bin
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:79ca983c89af32b5c38560d822324bf2023c3aa2b32ed17fd1ea67aac68b5166
|
||||||
|
size 1021613027
|
||||||
3
language_model/unigrams.txt
Normal file
3
language_model/unigrams.txt
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:c0f65403ece43fcc9eb95148060e402d7af46692f7a41a94b75ae23f40fa93d7
|
||||||
|
size 14815049
|
||||||
3198
log_mozilla-foundation_common_voice_7_0_fi_test_predictions.txt
Normal file
3198
log_mozilla-foundation_common_voice_7_0_fi_test_predictions.txt
Normal file
File diff suppressed because it is too large
Load Diff
3198
log_mozilla-foundation_common_voice_7_0_fi_test_targets.txt
Normal file
3198
log_mozilla-foundation_common_voice_7_0_fi_test_targets.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:90bd43ed41d3e2d6bac157e9c508ec22e43201893530145846abff96402d5fb9
|
||||||
|
size 3850270284
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
WER: 0.04094805849722642
|
||||||
|
CER: 0.00878705011729027
|
||||||
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.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:c3cb38ebbc92ea1f268e9f07b2f8ae488bf22c4239cbee763be91967c1d2d546
|
||||||
|
size 3850492081
|
||||||
1
run-finnish-asr-models.ipynb
Normal file
1
run-finnish-asr-models.ipynb
Normal file
File diff suppressed because one or more lines are too long
1
run_eval.sh
Normal file
1
run_eval.sh
Normal file
@@ -0,0 +1 @@
|
|||||||
|
python3 eval.py --dataset mozilla-foundation/common_voice_7_0 --config fi --model_id Finnish-NLP/wav2vec2-xlsr-1b-finnish-lm-v2 --split test --log_outputs
|
||||||
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}]}
|
||||||
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": "./", "tokenizer_class": "Wav2Vec2CTCTokenizer"}
|
||||||
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:fbef938211231011c68b88ab49363eeefca357ff111425e402c004dfe243d84a
|
||||||
|
size 3055
|
||||||
1
vocab.json
Normal file
1
vocab.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"'": 1, "a": 2, "b": 3, "c": 4, "d": 5, "e": 6, "f": 7, "g": 8, "h": 9, "i": 10, "j": 11, "k": 12, "l": 13, "m": 14, "n": 15, "o": 16, "p": 17, "q": 18, "r": 19, "s": 20, "t": 21, "u": 22, "v": 23, "w": 24, "x": 25, "y": 26, "z": 27, "ä": 28, "å": 29, "ö": 30, "|": 0, "[UNK]": 31, "[PAD]": 32}
|
||||||
Reference in New Issue
Block a user