gigant commited on
Commit
b3acab6
1 Parent(s): 17dedfd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +76 -5
README.md CHANGED
@@ -50,15 +50,86 @@ It achieves the following results on the evaluation set:
50
 
51
  ## Model description
52
 
53
- More information needed
54
 
55
- ## Intended uses & limitations
56
 
57
- More information needed
58
 
59
- ## Training and evaluation data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
 
61
- More information needed
62
 
63
  ## Training procedure
64
 
 
50
 
51
  ## Model description
52
 
53
+ The architecture is the same as [openai/whisper-medium](https://huggingface.co/openai/whisper-medium).
54
 
55
+ ## Training and evaluation data
56
 
57
+ The model was trained on the Common Voice 11.0 dataset (`train+validation+other splits`) and the Romanian speech synthesis corpus, and was tested on the `test` split of the Common Voice 11.0 dataset.
58
 
59
+ ## Usage
60
+ Inference with 🤗 Pipeline
61
+ ```python
62
+ import torch
63
+ from datasets import load_dataset
64
+ from transformers import pipeline
65
+
66
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
67
+ # Load pipeline
68
+ pipe = pipeline("automatic-speech-recognition", model="gigant/whisper-medium-romanian", device=device)
69
+ # NB: set forced_decoder_ids for generation utils
70
+ pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language="ro", task="transcribe")
71
+
72
+ # Load data
73
+ ds_mcv_test = load_dataset("mozilla-foundation/common_voice_11_0", "ro", split="test", streaming=True)
74
+ test_segment = next(iter(ds_mcv_test))
75
+ waveform = test_segment["audio"]
76
+
77
+ # NB: decoding option
78
+ # limit the maximum number of generated tokens to 225
79
+ pipe.model.config.max_length = 225 + 1
80
+ # sampling
81
+ # pipe.model.config.do_sample = True
82
+ # beam search
83
+ # pipe.model.config.num_beams = 5
84
+ # return
85
+ # pipe.model.config.return_dict_in_generate = True
86
+ # pipe.model.config.output_scores = True
87
+ # pipe.model.config.num_return_sequences = 5
88
+ # Run
89
+ generated_sentences = pipe(waveform)["text"]
90
+ ```
91
+ Inference with 🤗 low-level APIs
92
+ ```python
93
+ import torch
94
+ import torchaudio
95
+
96
+ from datasets import load_dataset
97
+ from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
98
+ device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
99
+
100
+ # Load model
101
+ model = AutoModelForSpeechSeq2Seq.from_pretrained("gigant/whisper-medium-romanian").to(device)
102
+ processor = AutoProcessor.from_pretrained("gigant/whisper-medium-romanian", language="romanian", task="transcribe")
103
+
104
+ # NB: set forced_decoder_ids for generation utils
105
+ model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language="ro", task="transcribe")
106
+ # 16_000
107
+ model_sample_rate = processor.feature_extractor.sampling_rate
108
+
109
+ # Load data
110
+ ds_mcv_test = load_dataset("mozilla-foundation/common_voice_11_0", "ro", split="test", streaming=True)
111
+ test_segment = next(iter(ds_mcv_test))
112
+ waveform = torch.from_numpy(test_segment["audio"]["array"])
113
+ sample_rate = test_segment["audio"]["sampling_rate"]
114
+ # Resample
115
+ if sample_rate != model_sample_rate:
116
+ resampler = torchaudio.transforms.Resample(sample_rate, model_sample_rate)
117
+ waveform = resampler(waveform)
118
+ # Get feat
119
+ inputs = processor(waveform, sampling_rate=model_sample_rate, return_tensors="pt")
120
+ input_features = inputs.input_features
121
+ input_features = input_features.to(device)
122
+
123
+ # Generate
124
+ generated_ids = model.generate(inputs=input_features, max_new_tokens=225) # greedy
125
+ # generated_ids = model.generate(inputs=input_features, max_new_tokens=225, num_beams=5) # beam search
126
+ # Detokenize
127
+ generated_sentences = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
128
+
129
+ # Normalise predicted sentences if necessary
130
+ ```
131
 
132
+ The code was adapted from [bofenghuang/deprecated-whisper-large-v2-cv11-french-punct-plus](https://huggingface.co/bofenghuang/deprecated-whisper-large-v2-cv11-french-punct-plus).
133
 
134
  ## Training procedure
135