Downloads · 30 days
6
17% of all-time downloads
Kang-Chieh/whisper-small-pitch_level
whisper-small-pitch_level is a machine learning model from Kang-Chieh. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
This model is a fine-tuned version of openai/whisper-small for single-label classification. It categorizes the perceived pitch level of an audio clip into one of three mutually exclusive classes.
Downloads · 30 days
6
17% of all-time downloads
All-time downloads
35
Public
Parameters
88.4M
353 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors353 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of openai/whisper-small for single-label classification. It categorizes the perceived pitch level of an audio clip into one of three mutually exclusive classes.
high-pitched: Relatively high perceived vocal pitch.medium-pitched: Moderate or neutral perceived vocal pitch.low-pitched: Relatively low perceived vocal pitch.WhisperProcessor for resampling and log-Mel feature extraction.openai/whisper-smallBecause this is a Single-Label task, the categories are mutually exclusive.
{
0: "high-pitched",
1: "medium-pitched",
2: "low-pitched",
}
import torch
import librosa
import numpy as np
from transformers import WhisperProcessor, WhisperForAudioClassification
model_id = "Kang-Chieh/whisper-small-pitch-level"
processor_id = "openai/whisper-small"
device = "cuda" if torch.cuda.is_available() else "cpu"
# Load the processor and model
processor = WhisperProcessor.from_pretrained(processor_id)
model = WhisperForAudioClassification.from_pretrained(model_id).to(device)
def predict_pitch(audio_path):
# 1. Load audio and ensure 16kHz mono audio
audio, _ = librosa.load(audio_path, sr=16000, mono=True)
# 2. Preprocess
inputs = processor(audio, sampling_rate=16000, return_tensors="pt")
input_features = inputs.input_features.to(device)
# 3. Inference
with torch.no_grad():
logits = model(input_features=input_features).logits
# 4. Single-label logic (Softmax)
probs = torch.softmax(logits, dim=-1).squeeze().cpu().numpy()
# 5. Get the highest scoring label
id2label = {int(k): v for k, v in model.config.id2label.items()}
predicted_id = int(np.argmax(probs))
return {
"label": id2label[predicted_id],
"confidence": float(probs[predicted_id]),
"all_scores": {id2label[i]: float(probs[i]) for i in range(len(probs))},
}
# Run example
result = predict_pitch("audio_clip.wav")
print(f"Detected Pitch: {result['label']} ({result['confidence']:.2%})")
From the saved evaluation results:
Class-wise summary:
high-pitched: precision 0.85, recall 0.66, f1-score 0.74medium-pitched: precision 0.59, recall 0.69, f1-score 0.64low-pitched: precision 0.66, recall 0.69, f1-score 0.67