Instructions to use AhmedZaky1/whisper-small-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AhmedZaky1/whisper-small-v1 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AhmedZaky1/whisper-small-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use AhmedZaky1/whisper-small-v1 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for AhmedZaky1/whisper-small-v1 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for AhmedZaky1/whisper-small-v1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for AhmedZaky1/whisper-small-v1 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="AhmedZaky1/whisper-small-v1", max_seq_length=2048, )
Update README.md
Browse files
README.md
CHANGED
|
@@ -11,10 +11,101 @@ language:
|
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
- **Developed by:** AhmedZaky1
|
| 17 |
-
- **License:** apache-2.0
|
| 18 |
-
- **Finetuned from model :** unsloth/whisper-small
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
| 11 |
- en
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Use Model
|
| 15 |
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
```
|
| 18 |
+
import torch
|
| 19 |
+
import numpy as np
|
| 20 |
+
import re
|
| 21 |
+
import jiwer
|
| 22 |
+
import librosa
|
| 23 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# TEXT NORMALIZATION
|
| 27 |
+
def normalize_text(text):
|
| 28 |
+
text = text.lower()
|
| 29 |
+
text = re.sub(r"[^\w\s]", "", text)
|
| 30 |
+
text = " ".join(text.split())
|
| 31 |
+
return text
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
# METRICS
|
| 35 |
+
def calculate_metrics(ref, hyp):
|
| 36 |
+
ref_n = normalize_text(ref)
|
| 37 |
+
hyp_n = normalize_text(hyp)
|
| 38 |
+
|
| 39 |
+
return {
|
| 40 |
+
"reference": ref_n,
|
| 41 |
+
"hypothesis": hyp_n,
|
| 42 |
+
"wer": jiwer.wer(ref_n, hyp_n),
|
| 43 |
+
"cer": jiwer.cer(ref_n, hyp_n)
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# LOAD MODEL FROM HF
|
| 48 |
+
def load_whisper(model_name, device="cuda"):
|
| 49 |
+
print(f"Loading Whisper model from HuggingFace: {model_name}")
|
| 50 |
+
|
| 51 |
+
processor = WhisperProcessor.from_pretrained(model_name)
|
| 52 |
+
model = WhisperForConditionalGeneration.from_pretrained(model_name)
|
| 53 |
+
|
| 54 |
+
return processor, model.to(device).eval()
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
# TRANSCRIBE AUDIO
|
| 58 |
+
def transcribe_audio(audio_path, processor, model, device="cuda"):
|
| 59 |
+
waveform, sr = librosa.load(audio_path, sr=16000)
|
| 60 |
+
|
| 61 |
+
inputs = processor(
|
| 62 |
+
waveform,
|
| 63 |
+
sampling_rate=sr,
|
| 64 |
+
return_tensors="pt"
|
| 65 |
+
).input_features.to(device)
|
| 66 |
+
|
| 67 |
+
with torch.no_grad():
|
| 68 |
+
predicted_ids = model.generate(inputs)
|
| 69 |
+
|
| 70 |
+
transcription = processor.batch_decode(
|
| 71 |
+
predicted_ids,
|
| 72 |
+
skip_special_tokens=True
|
| 73 |
+
)[0]
|
| 74 |
+
|
| 75 |
+
return transcription
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
# MAIN
|
| 79 |
+
def main():
|
| 80 |
+
# SET YOUR AUDIO FILE & REFERENCE TEXT HERE
|
| 81 |
+
audio_path = ""
|
| 82 |
+
reference_text = ""
|
| 83 |
+
|
| 84 |
+
# 2️ YOUR MODEL NAME
|
| 85 |
+
model_name = "AhmedZaky1/whisper-small-v1"
|
| 86 |
+
|
| 87 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 88 |
+
|
| 89 |
+
# Load model
|
| 90 |
+
processor, model = load_whisper(model_name, device)
|
| 91 |
+
|
| 92 |
+
# Transcribe
|
| 93 |
+
print("\nTranscribing audio...")
|
| 94 |
+
prediction = transcribe_audio(audio_path, processor, model, device)
|
| 95 |
+
|
| 96 |
+
# Compute metrics
|
| 97 |
+
metrics = calculate_metrics(reference_text, prediction)
|
| 98 |
+
|
| 99 |
+
print("\n==============================")
|
| 100 |
+
print("REFERENCE:", metrics["reference"])
|
| 101 |
+
print("PREDICTION:", metrics["hypothesis"])
|
| 102 |
+
print(f"WER: {metrics['wer'] * 100:.2f}%")
|
| 103 |
+
print(f"CER: {metrics['cer'] * 100:.2f}%")
|
| 104 |
+
print("==============================")
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
# Run script
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
main()
|
| 110 |
+
```
|
| 111 |
|