YassineKader
commited on
Commit
·
0a727d6
1
Parent(s):
adf1580
Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- ht
|
4 |
+
tags:
|
5 |
+
- audio
|
6 |
+
- automatic-speech-recognition
|
7 |
+
license: mit
|
8 |
+
library_name: ctranslate2
|
9 |
+
---
|
10 |
+
|
11 |
+
# Whisper small model for CTranslate2
|
12 |
+
|
13 |
+
This repository contains the conversion of [YassineKader/whisper-small-haitian](https://huggingface.co/YassineKader/whisper-small-haitian) to the [CTranslate2](https://github.com/OpenNMT/CTranslate2) model format.
|
14 |
+
|
15 |
+
This model can be used in CTranslate2 or projects based on CTranslate2 such as [faster-whisper](https://github.com/guillaumekln/faster-whisper).
|
16 |
+
|
17 |
+
## Example
|
18 |
+
|
19 |
+
```python
|
20 |
+
import ctranslate2
|
21 |
+
import librosa
|
22 |
+
import transformers
|
23 |
+
from datetime import datetime
|
24 |
+
# Load and resample the audio file.
|
25 |
+
audio, _ = librosa.load("audio1.wav", sr=16000, mono=True)
|
26 |
+
# Compute the features of the first 30 seconds of audio.
|
27 |
+
processor = transformers.WhisperProcessor.from_pretrained("YassineKader/whisper-small-haitian")
|
28 |
+
inputs = processor(audio, return_tensors="np", sampling_rate=16000)
|
29 |
+
features = ctranslate2.StorageView.from_array(inputs.input_features)
|
30 |
+
# Load the model on CPU.
|
31 |
+
model = ctranslate2.models.Whisper("whisper-small-HT")
|
32 |
+
# Detect the language.
|
33 |
+
results = model.detect_language(features)
|
34 |
+
language, probability = results[0][0]
|
35 |
+
print("Detected language %s with probability %f" % (language, probability))
|
36 |
+
print(datetime.now())
|
37 |
+
# Describe the task in the prompt.
|
38 |
+
# See the prompt format in https://github.com/openai/whisper.
|
39 |
+
prompt = processor.tokenizer.convert_tokens_to_ids(
|
40 |
+
[
|
41 |
+
"<|startoftranscript|>",
|
42 |
+
language,
|
43 |
+
"<|transcribe|>",
|
44 |
+
"<|notimestamps|>", # Remove this token to generate timestamps.
|
45 |
+
]
|
46 |
+
)
|
47 |
+
# Run generation for the 30-second window.
|
48 |
+
results = model.generate(features, [prompt])
|
49 |
+
transcription = processor.decode(results[0].sequences_ids[0])
|
50 |
+
|
51 |
+
print(datetime.now())
|
52 |
+
print(transcription)
|
53 |
+
```
|
54 |
+
|
55 |
+
## Conversion details
|
56 |
+
|
57 |
+
The original model was converted with the following command:
|
58 |
+
|
59 |
+
```
|
60 |
+
ct2-transformers-converter --model guillaumekln/faster-whisper-small --output_dir faster-whisper-small-ht --copy_files tokenizer.json --quantization float32
|
61 |
+
```
|
62 |
+
|
63 |
+
Note that the model weights are saved in FP16. This type can be changed when the model is loaded using the [`compute_type` option in CTranslate2](https://opennmt.net/CTranslate2/quantization.html).
|
64 |
+
|
65 |
+
## More information
|
66 |
+
|
67 |
+
**For more information about the original model, see its [model card](https://huggingface.co/openai/whisper-small).**
|