Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## KB-Whisper Medium (Beta)
|
2 |
+
|
3 |
+
Preliminary checkpoint of the National Library of Sweden's new Whisper models for Swedish.
|
4 |
+
|
5 |
+
### Usage
|
6 |
+
|
7 |
+
```python
|
8 |
+
import torch
|
9 |
+
from datasets import load_dataset
|
10 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
11 |
+
|
12 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
13 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
14 |
+
model_id = "KBLab/kb-whisper-medium-beta"
|
15 |
+
|
16 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
17 |
+
model_id, torch_dtype=torch_dtype, use_safetensors=True, cache_dir="cache"
|
18 |
+
)
|
19 |
+
model.to(device)
|
20 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
21 |
+
|
22 |
+
pipe = pipeline(
|
23 |
+
"automatic-speech-recognition",
|
24 |
+
model=model,
|
25 |
+
tokenizer=processor.tokenizer,
|
26 |
+
feature_extractor=processor.feature_extractor,
|
27 |
+
torch_dtype=torch_dtype,
|
28 |
+
device=device,
|
29 |
+
)
|
30 |
+
|
31 |
+
generate_kwargs = {"task": "transcribe", "language": "sv"}
|
32 |
+
# Add return_timestamps=True for output with timestamps
|
33 |
+
res = pipe("audio.mp3",
|
34 |
+
chunk_length_s=30,
|
35 |
+
generate_kwargs={"task": "transcribe", "language": "sv"})
|
36 |
+
```
|