File size: 3,715 Bytes
9ca6f51
750b095
57aabc7
750b095
 
 
 
 
 
 
 
 
 
7683a91
57aabc7
750b095
 
 
 
 
 
 
57aabc7
 
6901507
9ca6f51
 
750b095
 
9ca6f51
750b095
9ca6f51
59ee130
 
6901507
 
9ca6f51
750b095
9ca6f51
750b095
9ca6f51
750b095
9ca6f51
750b095
9ca6f51
750b095
9ca6f51
f3ce2c7
9ca6f51
750b095
f3ce2c7
9ca6f51
750b095
9ca6f51
750b095
 
 
 
 
 
 
 
 
 
 
 
9ca6f51
750b095
9ca6f51
750b095
 
6901507
 
 
 
 
9ca6f51
 
750b095
9ca6f51
750b095
 
 
 
f3ce2c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
base_model: facebook/w2v-bert-2.0
tags:
- generated_from_trainer
datasets:
- common_voice_7_0
metrics:
- wer
model-index:
- name: w2v-bert-2.0-luganda-CV-train-validation-7.0
  results:
  - task:
      name: Automatic Speech Recognition
      type: automatic-speech-recognition
    dataset:
      name: common_voice_7_0
      type: common_voice_7_0
      config: lg
      split: test
      args: lg
    metrics:
    - name: Wer
      type: wer
      value: 0.1933150003273751
---

<!-- 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. -->

# w2v-bert-2.0-luganda-CV-train-validation-7.0

This model is a fine-tuned version of [facebook/w2v-bert-2.0](https://huggingface.co/facebook/w2v-bert-2.0) on the Luganda mozilla common voices 7.0 dataset. We use the train and validation set for training and the test set for evaluation.
When using this dataset, make sure that the audio has a sampling rate of 16kHz.It achieves the following results on the test set:
- Loss: 0.2282
- Wer: 0.1933

## Model description

More information needed

## Intended uses & limitations

More information needed

## Training and evaluation data

The model was trained on version 7 of the Luganda dataset of Mozilla common voices dataset. We used the train and validation dataset for training and the test dataset for validation. 

## Training procedure
We trained the model on a 32 GB V100 GPU for 10 epochs using a learning rate of 5e-05. We used the AdamW optimizer. 

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 5e-05
- train_batch_size: 32
- eval_batch_size: 8
- seed: 42
- gradient_accumulation_steps: 2
- total_train_batch_size: 64
- optimizer: Adam 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

### Training results

| Training Loss | Epoch | Step | Validation Loss | Wer    |
|:-------------:|:-----:|:----:|:---------------:|:------:|
| 1.1859        | 1.89  | 300  | 0.2854          | 0.2866 |
| 0.1137        | 3.77  | 600  | 0.2503          | 0.2469 |
| 0.0712        | 5.66  | 900  | 0.2043          | 0.2092 |
| 0.0446        | 7.55  | 1200 | 0.2156          | 0.2005 |
| 0.0269        | 9.43  | 1500 | 0.2282          | 0.1933 |


### Framework versions

- Transformers 4.38.1
- Pytorch 2.2.1+cu121
- Datasets 2.17.0
- Tokenizers 0.15.2

### Usage
```python
import torch
import torchaudio
from datasets import load_dataset
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor

test_dataset = load_dataset("common_voice", "lg", split="test[:10]") 

processor = Wav2Vec2Processor.from_pretrained("dmusingu/w2v-bert-2.0-luganda-CV-train-validation-7.0") 
model = Wav2Vec2ForCTC.from_pretrained("dmusingu/w2v-bert-2.0-luganda-CV-train-validation-7.0")

resampler = torchaudio.transforms.Resample(48_000, 16_000)

# Preprocessing the datasets.
# We need to read the audio files as arrays
def speech_file_to_array_fn(batch):
    speech_array, sampling_rate = torchaudio.load(batch["path"])
    batch["speech"] = resampler(speech_array).squeeze().numpy()
    return batch

test_dataset = test_dataset.map(speech_file_to_array_fn)
inputs = processor(test_dataset[:2]["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)

with torch.no_grad():
    logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits

predicted_ids = torch.argmax(logits, dim=-1)

print("Prediction:", processor.batch_decode(predicted_ids))
print("Reference:", test_dataset["sentence"][:2])
```