Views
No views yet
pip install pyctcdecode
pip install https://github.com/kpu/kenlm/archive/master.zip1from transformers import pipeline
2
3# Load the model
4pipe = pipeline(model="vitouphy/wav2vec2-xls-r-300m-khmer")
5
6# Process raw audio
7output = pipe("sound_file.wav", chunk_length_s=10, stride_length_s=(4, 2))1from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
2import librosa
3import torch
4
5# load model and processor
6processor = Wav2Vec2Processor.from_pretrained("vitouphy/wav2vec2-xls-r-300m-khmer")
7model = Wav2Vec2ForCTC.from_pretrained("vitouphy/wav2vec2-xls-r-300m-khmer")
8
9# Read and process the input
10speech_array, sampling_rate = librosa.load("sound_file.wav", sr=16_000)
11inputs = processor(speech_array, sampling_rate=16_000, return_tensors="pt", padding=True)
12
13with torch.no_grad():
14 logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
15
16predicted_ids = torch.argmax(logits, axis=-1)
17predicted_sentences = processor.batch_decode(predicted_ids)
18print(predicted_sentences)| Training Loss | Epoch | Step | Validation Loss | Wer |
|---|---|---|---|---|
| 3.5671 | 5.47 | 400 | 12.0218 | 1.0 |
| 3.5159 | 10.95 | 800 | 10.6337 | 1.0 |
| 2.4543 | 16.43 | 1200 | 1.8256 | 0.9839 |
| 1.9437 | 21.91 | 1600 | 1.1237 | 0.9173 |
| 1.696 | 27.39 | 2000 | 0.8246 | 0.7700 |
| 1.5342 | 32.87 | 2400 | 0.6433 | 0.6594 |
| 1.4509 | 38.35 | 2800 | 0.5500 | 0.5787 |
| 1.3478 | 43.83 | 3200 | 0.5070 | 0.4907 |
| 1.3096 | 49.31 | 3600 | 0.4692 | 0.4726 |
| 1.2532 | 54.79 | 4000 | 0.4448 | 0.4479 |
| 1.2291 | 60.27 | 4400 | 0.4374 | 0.4366 |
| 1.196 | 65.75 | 4800 | 0.4314 | 0.4310 |
| 1.1862 | 71.23 | 5200 | 0.4239 | 0.4221 |