Oblivion208 commited on
Commit
3a521bf
1 Parent(s): 41fe0a6

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +33 -0
README.md CHANGED
@@ -14,6 +14,39 @@ pipeline_tag: automatic-speech-recognition
14
  🤗 <a href="https://huggingface.co/Oblivion208" target="_blank">HF Repo</a> •🐱 <a href="https://github.com/fengredrum/finetune-whisper-lora" target="_blank">Github Repo</a>
15
  </p>
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  ## Approximate Performance Evaluation
18
 
19
  The following models are all trained and evaluated on a single RTX 3090 GPU.
 
14
  🤗 <a href="https://huggingface.co/Oblivion208" target="_blank">HF Repo</a> •🐱 <a href="https://github.com/fengredrum/finetune-whisper-lora" target="_blank">Github Repo</a>
15
  </p>
16
 
17
+ ## Usage
18
+ ```python
19
+ import torch
20
+ import librosa
21
+ from transformers import WhisperProcessor, WhisperTokenizer, WhisperForConditionalGeneration
22
+
23
+ # Setups
24
+ model_name_or_path = "Oblivion208/whisper-tiny-cantonese"
25
+ task = "transcribe"
26
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
27
+
28
+ model = WhisperForConditionalGeneration.from_pretrained(model_name_or_path).to(device)
29
+ tokenizer = WhisperTokenizer.from_pretrained(model_name_or_path, task=task)
30
+ processor = WhisperProcessor.from_pretrained(model_name_or_path, task=task)
31
+ feature_extractor = processor.feature_extractor
32
+ model.config.forced_decoder_ids = None
33
+ model.config.suppress_tokens = []
34
+
35
+ filepath = 'test.wav'
36
+ audio, sr = librosa.load(filepath, sr=16000, mono=True)
37
+ inputs = processor(audio, sample_rate=sr, return_tensors="pt").to(device)
38
+
39
+ with torch.inference_mode():
40
+ generated_tokens = model.generate(
41
+ input_features=inputs.input_features,
42
+ return_dict_in_generate=True,
43
+ max_new_tokens=255,
44
+ )
45
+ transcription = tokenizer.batch_decode(
46
+ generated_tokens.sequences, skip_special_tokens=True)
47
+ print(transcription)
48
+ ```
49
+
50
  ## Approximate Performance Evaluation
51
 
52
  The following models are all trained and evaluated on a single RTX 3090 GPU.