ghananlpcommunity/ghana-speech
Viewer โข Updated โข 1.41M โข 4.01k โข 4
How to use saanimustaf/twi-asr-fixed-grapheme-mms300m with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("automatic-speech-recognition", model="saanimustaf/twi-asr-fixed-grapheme-mms300m") # pip install -U transformers accelerate
# Load model directly
from transformers import AutoProcessor, AutoModelForCTC
processor = AutoProcessor.from_pretrained("saanimustaf/twi-asr-fixed-grapheme-mms300m")
model = AutoModelForCTC.from_pretrained("saanimustaf/twi-asr-fixed-grapheme-mms300m", device_map="auto")This model is a fine-tuned version of facebook/mms-300m for Automatic Speech Recognition (ASR) on Asante Twi.
The training transcripts were normalized using the twi-grapheme-fixer before training.
facebook/mms-300mtw)twi-grapheme-fixerAsante_Twi_twi| Hyperparameter | Value |
|---|---|
| Learning rate | 1e-4 |
| Batch size | 8 |
| Gradient accumulation steps | 2 |
| Effective batch size | 16 |
| Warmup steps | 300 |
| Number of epochs (reported) | 10 |
| FP16 | Yes |
| Gradient checkpointing | Yes |
| Feature encoder | Frozen |
| Evaluation strategy | epoch |
| Metric for best model | CER |
| Epoch | Training Loss | Validation Loss | CER | WER |
|---|---|---|---|---|
| 1 | 4.234 | 4.405 | 1.000 | 1.000 |
| 2 | 3.400 | 3.334 | 1.000 | 1.000 |
| 3 | 3.280 | 3.166 | 0.986 | 1.000 |
| 4 | 3.175 | 3.171 | 0.987 | 1.000 |
| 5 | 2.741 | 2.754 | 0.907 | 1.000 |
| 6 | 1.709 | 1.504 | 0.442 | 0.970 |
| 7 | 1.208 | 1.130 | 0.296 | 0.785 |
| 8 | 0.912 | 0.881 | 0.215 | 0.642 |
| 9 | 0.821 | 0.773 | 0.210 | 0.615 |
| 10 | 0.901 | 0.784 | 0.206 | 0.613 |
This is a research / pilot model. It was trained on a relatively small subset of the Ghana Speech dataset and should not be considered production-ready.
from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
import torch
import torchaudio
model_id = "saanimustaf/twi-asr-fixed-grapheme-mms300m"
processor = Wav2Vec2Processor.from_pretrained(model_id)
model = Wav2Vec2ForCTC.from_pretrained(model_id)
# Load and resample audio to 16 kHz
speech, sr = torchaudio.load("path/to/audio.wav")
if sr != 16000:
speech = torchaudio.functional.resample(speech, sr, 16000)
inputs = processor(speech.squeeze().numpy(), sampling_rate=16000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(**inputs).logits
predicted_ids = torch.argmax(logits, dim=-1)
transcription = processor.batch_decode(predicted_ids)[0]
print(transcription)