alvanlii commited on
Commit
72b901d
1 Parent(s): b560801

Add model usage instructions

Browse files
Files changed (1) hide show
  1. README.md +40 -0
README.md CHANGED
@@ -37,6 +37,46 @@ For training, three datasets were used:
37
  - CantoMap: Winterstein, Grégoire, Tang, Carmen and Lai, Regine (2020) "CantoMap: a Hong Kong Cantonese MapTask Corpus", in Proceedings of The 12th Language Resources and Evaluation Conference, Marseille: European Language Resources Association, p. 2899-2906.
38
  - Cantonse-ASR: Yu, Tiezheng, Frieske, Rita, Xu, Peng, Cahyawijaya, Samuel, Yiu, Cheuk Tung, Lovenia, Holy, Dai, Wenliang, Barezi, Elham, Chen, Qifeng, Ma, Xiaojuan, Shi, Bertram, Fung, Pascale (2022) "Automatic Speech Recognition Datasets in Cantonese: A Survey and New Dataset", 2022. Link: https://arxiv.org/pdf/2201.02419.pdf
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  ## Training Hyperparameters
41
  - learning_rate: 5e-5
42
  - train_batch_size: 25 (on 2 GPUs)
 
37
  - CantoMap: Winterstein, Grégoire, Tang, Carmen and Lai, Regine (2020) "CantoMap: a Hong Kong Cantonese MapTask Corpus", in Proceedings of The 12th Language Resources and Evaluation Conference, Marseille: European Language Resources Association, p. 2899-2906.
38
  - Cantonse-ASR: Yu, Tiezheng, Frieske, Rita, Xu, Peng, Cahyawijaya, Samuel, Yiu, Cheuk Tung, Lovenia, Holy, Dai, Wenliang, Barezi, Elham, Chen, Qifeng, Ma, Xiaojuan, Shi, Bertram, Fung, Pascale (2022) "Automatic Speech Recognition Datasets in Cantonese: A Survey and New Dataset", 2022. Link: https://arxiv.org/pdf/2201.02419.pdf
39
 
40
+ ## Using the Model
41
+ ```
42
+ import librosa
43
+
44
+ import torch
45
+ from transformers import WhisperForConditionalGeneration, WhisperProcessor
46
+
47
+ y, sr = librosa.load('audio.mp3', sr=16000)
48
+
49
+ MODEL_NAME = "alvanlii/whisper-small-cantonese"
50
+
51
+ processor = WhisperProcessor.from_pretrained(MODEL_NAME)
52
+ model = WhisperForConditionalGeneration.from_pretrained(MODEL_NAME)
53
+
54
+ model.config.forced_decoder_ids = None
55
+ model.config.suppress_tokens = []
56
+ model.config.use_cache = False
57
+
58
+ processed_in = processor(y, sampling_rate=sr, return_tensors="pt")
59
+ gout = model.generate(
60
+ input_features=processed_in.input_features,
61
+ output_scores=True, return_dict_in_generate=True
62
+ )
63
+ transcription = processor.batch_decode(gout.sequences, skip_special_tokens=True)[0]
64
+ print(transcription)
65
+ ```
66
+ - Alternatively, you can use huggingface pipelines
67
+ ```
68
+ from transformers import pipeline
69
+ MODEL_NAME = "alvanlii/whisper-small-cantonese"
70
+ lang = "zh"
71
+ pipe = pipeline(
72
+ task="automatic-speech-recognition",
73
+ model=MODEL_NAME,
74
+ chunk_length_s=30,
75
+ device=device,
76
+ )
77
+ pipe.model.config.forced_decoder_ids = pipe.tokenizer.get_decoder_prompt_ids(language=lang, task="transcribe")
78
+ text = pipe(file)["text"]
79
+ ```
80
  ## Training Hyperparameters
81
  - learning_rate: 5e-5
82
  - train_batch_size: 25 (on 2 GPUs)