File size: 5,947 Bytes
a8f9c20 6f59045 a8f9c20 6f59045 a8f9c20 0e3b9d4 a8f9c20 0e3b9d4 a8f9c20 0e3b9d4 a8f9c20 6f59045 a8f9c20 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
---
license: apache-2.0
tags:
- generated_from_trainer
metrics:
- wer
model-index:
- name: whisper-small-spanish
results: []
---
<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->
# whisper-small-sp
This model is a fine-tuned version of [openai/whisper-small](https://huggingface.co/openai/whisper-small) on the `commonvoice dataset v11` dataset.
It achieves the following results on the evaluation set:
- Loss: 0.4485
- Wer: 20.6842
## Model description
More information needed
## Intended uses & limitations
More information needed
## Training and evaluation data
More information needed
## Training procedure
### Training hyperparameters
The following hyperparameters were used during training:
- learning_rate: 0.0005
- train_batch_size: 16
- eval_batch_size: 8
- seed: 42
- optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
- lr_scheduler_type: linear
- lr_scheduler_warmup_steps: 500
- training_steps: 25000
- mixed_precision_training: Native AMP
### Training results
| Training Loss | Epoch | Step | Validation Loss | Wer |
|:-------------:|:-----:|:-----:|:---------------:|:-------:|
| 2.2671 | 0.13 | 1000 | 2.2108 | 76.2667 |
| 1.4465 | 0.26 | 2000 | 1.6057 | 67.8753 |
| 1.0997 | 0.39 | 3000 | 1.1928 | 54.2433 |
| 0.9389 | 0.52 | 4000 | 1.0020 | 47.8307 |
| 0.7881 | 0.65 | 5000 | 0.8933 | 46.0046 |
| 0.7596 | 0.78 | 6000 | 0.7721 | 38.5595 |
| 0.5678 | 0.91 | 7000 | 0.6903 | 36.2897 |
| 0.4412 | 1.04 | 8000 | 0.6476 | 32.7473 |
| 0.4239 | 1.17 | 9000 | 0.5973 | 30.8142 |
| 0.3935 | 1.3 | 10000 | 0.5444 | 29.0208 |
| 0.3307 | 1.43 | 11000 | 0.5024 | 27.0434 |
| 0.2937 | 1.56 | 12000 | 0.4608 | 24.7318 |
| 0.2471 | 1.69 | 13000 | 0.4259 | 22.8940 |
| 0.2357 | 1.82 | 14000 | 0.3936 | 21.6018 |
| 0.2292 | 1.95 | 15000 | 0.3776 | 20.8004 |
| 0.1493 | 2.08 | 16000 | 0.4599 | 24.0491 |
| 0.1708 | 2.21 | 17000 | 0.4370 | 23.3443 |
| 0.1385 | 2.34 | 18000 | 0.4277 | 22.3171 |
| 0.1288 | 2.47 | 19000 | 0.4050 | 21.0118 |
| 0.1627 | 2.6 | 20000 | 0.4507 | 23.4004 |
| 0.1675 | 2.73 | 21000 | 0.4346 | 22.8261 |
| 0.159 | 2.86 | 22000 | 0.4179 | 22.2949 |
| 0.1458 | 2.99 | 23000 | 0.3978 | 21.0810 |
| 0.0487 | 3.12 | 24000 | 0.4456 | 20.8617 |
| 0.0401 | 3.25 | 25000 | 0.4485 | 20.6842 |
### Transcription:
```python
from datasets import load_dataset, Audio
import torch
from transformers import WhisperProcessor, WhisperForConditionalGeneration
# device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# load the model
processor = WhisperProcessor.from_pretrained("clu-ling/whisper-small-spanish")
model = WhisperForConditionalGeneration.from_pretrained("clu-ling/whisper-small-spanish").to(device)
forced_decoder_ids = processor.get_decoder_prompt_ids(language="es", task="transcribe")
# load the dataset
commonvoice_eval = load_dataset("mozilla-foundation/common_voice_11_0", "es", split="validation", streaming=True)
commonvoice_eval = commonvoice_eval.cast_column("audio", Audio(sampling_rate=16000))
sample = next(iter(commonvoice_eval))["audio"]
# features and generate token ids
input_features = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features
predicted_ids = model.generate(input_features.to(device), forced_decoder_ids=forced_decoder_ids)
# decode
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
print(transcription)
```
### Evaluation:
Evaluates this model on `mozilla-foundation/common_voice_11_0` test split.
```python
from transformers.models.whisper.english_normalizer import BasicTextNormalizer
from datasets import load_dataset, Audio
import evaluate
import torch
import re
from transformers import WhisperProcessor, WhisperForConditionalGeneration
# device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# metric
wer_metric = evaluate.load("wer")
# model
processor = WhisperProcessor.from_pretrained("clu-ling/whisper-small-spanish")
model = WhisperForConditionalGeneration.from_pretrained("clu-ling/whisper-small-spanish")
# dataset
dataset = load_dataset("mozilla-foundation/common_voice_11_0", "es", split="test", )#cache_dir=args.cache_dir
dataset = dataset.cast_column("audio", Audio(sampling_rate=16000))
#for debuggings: it gets some examples
#dataset = dataset.shard(num_shards=10000, index=0)
#print(dataset)
def normalize(batch):
batch["gold_text"] = whisper_norm(batch['sentence'])
return batch
def map_wer(batch):
model.to(device)
forced_decoder_ids = processor.get_decoder_prompt_ids(language = "es", task = "transcribe")
inputs = processor(batch["audio"]["array"], sampling_rate=batch["audio"]["sampling_rate"], return_tensors="pt").input_features
with torch.no_grad():
generated_ids = model.generate(inputs=inputs.to(device), forced_decoder_ids=forced_decoder_ids)
transcription = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
batch["predicted_text"] = whisper_norm(transcription)
return batch
# process GOLD text
processed_dataset = dataset.map(normalize)
# get predictions
predicted = processed_dataset.map(map_wer)
# word error rate
wer = wer_metric.compute(references=predicted['gold_text'], predictions=predicted['predicted_text'])
wer = round(100 * wer, 2)
print("WER:", wer)
```
### Framework versions
- Transformers 4.25.1
- Pytorch 1.13.0+cu117
- Datasets 2.7.1
- Tokenizers 0.13.2
|