Views
No views yet
| dev | test | |
|---|---|---|
| WER | 0.295206 | 0.290094 |
| CER | 0.140766 | 0.137642 |
transformerstransformers==4.18.0, torch==1.11.0, and SoundFile==0.10.3.post1.1from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
2import soundfile as sf
3import torch
4import os
5
6device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
7
8# load model and tokenizer
9processor = Wav2Vec2Processor.from_pretrained(
10 "classla/wav2vec2-xls-r-juznevesti-sr")
11model = Wav2Vec2ForCTC.from_pretrained("classla/wav2vec2-xls-r-juznevesti-sr")
12
13
14# download the example wav files:
15os.system("wget https://huggingface.co/classla/wav2vec2-xls-r-parlaspeech-hr/raw/main/00020570a.flac.wav")
16
17# read the wav file
18speech, sample_rate = sf.read("00020570a.flac.wav")
19input_values = processor(speech, sampling_rate=sample_rate, return_tensors="pt").input_values.to(device)
20
21# remove the raw wav file
22os.system("rm 00020570a.flac.wav")
23
24# retrieve logits
25logits = model.to(device)(input_values).logits
26
27# take argmax and decode
28predicted_ids = torch.argmax(logits, dim=-1)
29transcription = processor.decode(predicted_ids[0])
30
31transcription # 'velik broj poslovnih subjekata posluje sa minosom velik deo'| arg | value |
|---|---|
per_device_train_batch_size | 16 |
gradient_accumulation_steps | 4 |
num_train_epochs | 20 |
learning_rate | 3e-4 |
warmup_steps | 500 |