Downloads · 30 days
15
13% of all-time downloads
marshal-yash/SER_wav2vec
SER_wav2vec is a audio classification model from marshal-yash. Use it for the audio classification task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
- Architecture: Wav2Vec2 encoder with a sequence classification head (Wav2Vec2ForSequenceClassification). - Sampling rate: 16 kHz mono inputs. - Label set: angry, calm, disgust, fear, happy, neutral, sad, surprise. -…
Downloads · 30 days
15
13% of all-time downloads
All-time downloads
117
Public
Parameters
94.6M
378 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors378 MB · 100%
From the Hugging Face model README
Wav2Vec2ForSequenceClassification).angry, calm, disgust, fear, happy, neutral, sad, surprise.facebook/wav2vec2-base-960h fine‑tuned for emotion classification.confit/cremad-parquet).import torch, numpy as np, soundfile as sf, librosa
from transformers import Wav2Vec2ForSequenceClassification, AutoFeatureExtractor
model_dir = "path/to/best_model" # local directory or Hub repo id
model = Wav2Vec2ForSequenceClassification.from_pretrained(model_dir)
fe = AutoFeatureExtractor.from_pretrained(model_dir)
model.eval()
def load_audio(path, sr=fe.sampling_rate):
y, s = sf.read(path, always_2d=False)
if isinstance(y, np.ndarray):
if y.ndim > 1:
y = np.mean(y, axis=1)
if s != sr:
y = librosa.resample(y.astype(np.float32), orig_sr=s, target_sr=sr)
y = y.astype(np.float32)
else:
y = np.array(y, dtype=np.float32)
if y.size < sr // 10:
y = np.pad(y, (0, max(0, sr - y.size)))
return y
audio = load_audio("sample.wav")
inputs = fe(audio, sampling_rate=fe.sampling_rate, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1)[0].cpu().numpy()
labels = [model.config.id2label[str(i)] if isinstance(list(model.config.id2label.keys())[0], str) else model.config.id2label[i] for i in range(len(probs))]
pairs = sorted(zip(labels, probs), key=lambda x: x[1], reverse=True)
print(pairs[:3])
This repository includes a FastAPI server that exposes POST /predict and returns sorted label probabilities and the dominant emotion.
wav, mp3, m4a, etc.). Internally converted to 16 kHz mono.{
"results": [{ "label": "happy", "score": 0.81 }, ...],
"dominant": { "label": "happy", "score": 0.81 }
}
If you use this model, please cite:
MIT