Downloads · 30 days
5K
1% of all-time downloads
Dpngtm/wav2vec2-emotion-recognition
wav2vec2-emotion-recognition is a audio classification model from Dpngtm. 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.
This model is a fine-tuned version of facebook/wav2vec2-base-960h for Speech Emotion Recognition (SER).
Downloads · 30 days
5K
1% of all-time downloads
All-time downloads
449K
Public
Parameters
94.6M
34.1 GB on disk
Likes
7
Public
Click a slice to open those files.
.safetensors378 MB · 100%
From the Hugging Face model README
This model is a fine-tuned version of facebook/wav2vec2-base-960h for Speech Emotion Recognition (SER).
It has been trained using a Frozen Feature Extractor strategy to preserve the model's acoustic understanding while adapting to emotion detection. This approach ensures stable performance and prevents "Catastrophic Forgetting," achieving nearly 80% accuracy on the validation set.
Update: The "Calm" and "Neutral" classes have been merged to improve classification consistency, resulting in 7 distinct emotion classes.
facebook/wav2vec2-base-960hThe model was trained on a combined dataset of ~12,000 audio files from:
| Metric | Score |
|---|---|
| Accuracy | 79.94% |
| F1 Score | 79.65% |
| Validation Loss | 0.644 |
Note: Achieved stable convergence using a Cosine Learning Rate Scheduler and Frozen Feature Extractor.
The model classifies audio into one of the following emotions:
The model was fine-tuned using the following "Robust" configuration to ensure stability on Google Colab T4 GPUs:
Try the model in your browser: 👉 Hugging Face Space: Audio Emotion Recognition
For issues and questions, feel free to:
from transformers import AutoModelForAudioClassification, Wav2Vec2Processor
import torch
import torchaudio
import numpy as np
# 1. Load Model and Processor
model_id = "Dpngtm/wav2vec2-emotion-recognition"
model = AutoModelForAudioClassification.from_pretrained(model_id)
processor = Wav2Vec2Processor.from_pretrained(model_id)
# 2. Load Audio
# Replace with your file path
audio_path = "path_to_audio.wav"
speech_array, sampling_rate = torchaudio.load(audio_path)
# 3. Resample to 16kHz (CRITICAL STEP)
if sampling_rate != 16000:
resampler = torchaudio.transforms.Resample(sampling_rate, 16000)
speech_array = resampler(speech_array)
sampling_rate = 16000
# 4. Handle Stereo (Convert to Mono)
if speech_array.shape[0] > 1:
speech_array = torch.mean(speech_array, dim=0, keepdim=True)
# 5. Process & Predict
inputs = processor(speech_array.squeeze(), sampling_rate=16000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(**inputs).logits
# 6. Decode Result
predicted_id = torch.argmax(logits, dim=-1).item()
id2label = model.config.id2label
predicted_label = id2label[predicted_id]
print(f"Predicted Emotion: {predicted_label}")