Introduction of w2v-bert-2.0-luganda-CV-train-validation-7.0
Model Details of w2v-bert-2.0-luganda-CV-train-validation-7.0
w2v-bert-2.0-luganda-CV-train-validation-7.0
This model is a fine-tuned version of
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
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 set for training and the test dataset for validation. The
training script
was adapted from this
transformers repo
.
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
import torch
import torchaudio
from datasets import load_dataset
from transformers import AutoModelForCTC, Wav2Vec2BertProcessor
test_dataset = load_dataset("common_voice", "lg", split="test[:10]")
model = AutoModelForCTC.from_pretrained("dmusingu/w2v-bert-2.0-luganda-CV-train-validation-7.0")
processor = Wav2Vec2BertProcessor.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 arraysdefspeech_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])
Evaluation
The model can be evaluated as follows on the Luganda test dataset.
import torch
import torchaudio
from datasets import load_dataset, load_metric
from transformers import AutoModelForCTC, Wav2Vec2BertProcessor
import re
test_dataset = load_dataset("common_voice", "lg", split="test")
wer = load_metric("wer")
model = AutoModelForCTC.from_pretrained("dmusingu/w2v-bert-2.0-luganda-CV-train-validation-7.0").to('cuda')
processor = Wav2Vec2BertProcessor.from_pretrained("dmusingu/w2v-bert-2.0-luganda-CV-train-validation-7.0")
chars_to_remove_regex = '[\,\?\.\!\-\;\:\"\“\%\‘\”\�\'\»\«]'
test_dataset = test_dataset.cast_column("audio", Audio(sampling_rate=16_000))
defremove_special_characters(batch):
# remove special characters
batch["sentence"] = re.sub(chars_to_remove_regex, '', batch["sentence"]).lower()
return batch
test_dataset = test_dataset.map(remove_special_characters)
defprepare_dataset(batch):
audio = batch["audio"]
batch["input_features"] = processor(audio["array"], sampling_rate=audio["sampling_rate"]).input_features[0]
batch["input_length"] = len(batch["input_features"])
batch["labels"] = processor(text=batch["sentence"]).input_ids
return batch
test_dataset = test_dataset.map(prepare_dataset, remove_columns=test_dataset.column_names)
# Evaluation is carried out with a batch size of 1defmap_to_result(batch):
with torch.no_grad():
input_values = torch.tensor(batch["input_features"], device="cuda").unsqueeze(0)
logits = model(input_values).logits
pred_ids = torch.argmax(logits, dim=-1)
batch["pred_str"] = processor.batch_decode(pred_ids)[0]
batch["text"] = processor.decode(batch["labels"], group_tokens=False)
return batch
results = test_dataset.map(map_to_result)
print("Test WER: {:.3f}".format(wer_metric.compute(predictions=results["pred_str"], references=results["text"])))
Test Result: 19.33%
Runs of dmusingu w2v-bert-2.0-luganda-CV-train-validation-7.0 on huggingface.co
22
Total runs
0
24-hour runs
-1
3-day runs
-1
7-day runs
10
30-day runs
More Information About w2v-bert-2.0-luganda-CV-train-validation-7.0 huggingface.co Model
More w2v-bert-2.0-luganda-CV-train-validation-7.0 license Visit here:
w2v-bert-2.0-luganda-CV-train-validation-7.0 huggingface.co is an AI model on huggingface.co that provides w2v-bert-2.0-luganda-CV-train-validation-7.0's model effect (), which can be used instantly with this dmusingu w2v-bert-2.0-luganda-CV-train-validation-7.0 model. huggingface.co supports a free trial of the w2v-bert-2.0-luganda-CV-train-validation-7.0 model, and also provides paid use of the w2v-bert-2.0-luganda-CV-train-validation-7.0. Support call w2v-bert-2.0-luganda-CV-train-validation-7.0 model through api, including Node.js, Python, http.
w2v-bert-2.0-luganda-CV-train-validation-7.0 huggingface.co is an online trial and call api platform, which integrates w2v-bert-2.0-luganda-CV-train-validation-7.0's modeling effects, including api services, and provides a free online trial of w2v-bert-2.0-luganda-CV-train-validation-7.0, you can try w2v-bert-2.0-luganda-CV-train-validation-7.0 online for free by clicking the link below.
dmusingu w2v-bert-2.0-luganda-CV-train-validation-7.0 online free url in huggingface.co:
w2v-bert-2.0-luganda-CV-train-validation-7.0 is an open source model from GitHub that offers a free installation service, and any user can find w2v-bert-2.0-luganda-CV-train-validation-7.0 on GitHub to install. At the same time, huggingface.co provides the effect of w2v-bert-2.0-luganda-CV-train-validation-7.0 install, users can directly use w2v-bert-2.0-luganda-CV-train-validation-7.0 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.
w2v-bert-2.0-luganda-CV-train-validation-7.0 install url in huggingface.co: