Kosuke-Szk commited on
Commit
6b04853
β€’
1 Parent(s): 095a397

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +52 -0
README.md CHANGED
@@ -1,3 +1,55 @@
1
  ---
2
  license: apache-2.0
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: apache-2.0
3
+ datasets:
4
+ - common_voice
5
+ language:
6
+ - ja
7
+ tags:
8
+ - audio
9
  ---
10
+
11
+ # Fine-tuned Japanese Whisper model for speech recognition using whisper-small
12
+ Fine-tuned [openai/whisper-small](https://huggingface.co/openai/whisper-small) on Japanese using [Common Voice](https://commonvoice.mozilla.org/ja/datasets), [JVS](https://sites.google.com/site/shinnosuketakamichi/research-topics/jvs_corpus) and [JSUT](https://sites.google.com/site/shinnosuketakamichi/publication/jsut).
13
+ When using this model, make sure that your speech input is sampled at 16kHz.
14
+
15
+ ## Usage
16
+ The model can be used directly as follows.
17
+ ```python
18
+ from transformers import WhisperForConditionalGeneration, WhisperProcessor
19
+ from datasets import load_dataset
20
+ import librosa
21
+ import torch
22
+
23
+ LANG_ID = "ja"
24
+ MODEL_ID = "Ivydata/whisper-small-japanese"
25
+ SAMPLES = 10
26
+
27
+ test_dataset = load_dataset("common_voice", LANG_ID, split=f"test[:{SAMPLES}]")
28
+ processor = WhisperProcessor.from_pretrained("openai/whisper-base")
29
+ model = WhisperForConditionalGeneration.from_pretrained(MODEL_ID)
30
+ model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(
31
+ language="ja", task="transcribe"
32
+ )
33
+ model.config.suppress_tokens = []
34
+
35
+ # Preprocessing the datasets.
36
+ # We need to read the audio files as arrays
37
+ def speech_file_to_array_fn(batch):
38
+ speech_array, sampling_rate = librosa.load(batch["path"], sr=16_000)
39
+ batch["speech"] = speech_array
40
+ batch["sentence"] = batch["sentence"].upper()
41
+ batch["sampling_rate"] = sampling_rate
42
+ return batch
43
+
44
+ test_dataset = test_dataset.map(speech_file_to_array_fn)
45
+ sample = test_dataset[0]
46
+ input_features = processor(sample["speech"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features
47
+ predicted_ids = model.generate(input_features)
48
+
49
+ transcription = processor.batch_decode(predicted_ids, skip_special_tokens=False)
50
+ # ['<|startoftranscript|><|ja|><|transcribe|><|notimestamps|>ζœ¨ζ‘γ•γ‚“γ«ι›»θ©±γ‚’θ²Έγ—γ¦γ‚‚γ‚‰γ„γΎγ—γŸγ€‚<|endoftext|>']
51
+
52
+ transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
53
+ # ['ζœ¨ζ‘γ•γ‚“γ«ι›»θ©±γ‚’θ²Έγ—γ¦γ‚‚γ‚‰γ„γΎγ—γŸγ€‚']
54
+
55
+ ```