5roop commited on
Commit
cce5842
1 Parent(s): e84eba9

Added an use example

Browse files
Files changed (1) hide show
  1. README.md +41 -1
README.md CHANGED
@@ -19,4 +19,44 @@ This model is based on the [facebook/wav2vec2-xls-r-300m model](https://huggingf
19
 
20
  The efforts resulting with this model were coordinated by Nikola Ljubešić, the rough manual data alignment was performed by Ivo-Pavao Jazbec, the method for fine automatic data alignment from [Plüss et al.](https://arxiv.org/abs/2010.02810) was applied by Vuk Batanović and Lenka Bajčetić, while the final modelling was performed by Peter Rupnik.
21
 
22
- Initial evaluation on partially noisy data showed the model to achieve a word error rate of 13.68% and a character error rate of 4.56%.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
  The efforts resulting with this model were coordinated by Nikola Ljubešić, the rough manual data alignment was performed by Ivo-Pavao Jazbec, the method for fine automatic data alignment from [Plüss et al.](https://arxiv.org/abs/2010.02810) was applied by Vuk Batanović and Lenka Bajčetić, while the final modelling was performed by Peter Rupnik.
21
 
22
+ Initial evaluation on partially noisy data showed the model to achieve a word error rate of 13.68% and a character error rate of 4.56%.
23
+
24
+ ## Usage in `transformers`
25
+
26
+ ```python
27
+ from transformers import Wav2Vec2Processor, Wav2Vec2ForCTC
28
+ from datasets import Audio
29
+ import soundfile as sf
30
+ import torch
31
+ import os
32
+
33
+ # load model and tokenizer
34
+ processor = Wav2Vec2Processor.from_pretrained(
35
+ "classla/wav2vec2-xls-r-sabor-hr")
36
+ model = Wav2Vec2ForCTC.from_pretrained("classla/wav2vec2-xls-r-sabor-hr")
37
+
38
+
39
+ # download the example wav files:
40
+ os.system("curl https://huggingface.co/classla/wav2vec2-xls-r-sabor-hr/raw/main/00020570a.flac.wav")
41
+
42
+ # read the wav file as datasets.Audio object
43
+ audio = Audio(sampling_rate=16000).decode_example("00020570a.flac.wav")
44
+
45
+ # remove the raw wav file
46
+ os.system("rm 00020570a.flac.wav")
47
+
48
+ # tokenize
49
+ input_values = processor(
50
+ audio["array"], return_tensors="pt", padding=True,
51
+ sampling_rate=16000).input_values
52
+
53
+ # retrieve logits
54
+ logits = model(input_values).logits
55
+
56
+ # take argmax and decode
57
+ predicted_ids = torch.argmax(logits, dim=-1)
58
+ transcription = processor.batch_decode(predicted_ids)
59
+
60
+
61
+ # transcription: ['veliki broj poslovnih subjekata posluje sa minusom velik dio']
62
+ ```