File size: 5,517 Bytes
b575114 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
---
language:
- en
license: mit
library_name: transformers
tags:
- audio
- emotion-classification
- arousal-valence
- speech
- pytorch
- custom
pipeline_tag: audio-classification
datasets:
- TESS
- CREMA-D
metrics:
- accuracy
- mse
model-index:
- name: emotion-av-model
results:
- task:
type: audio-classification
name: Audio Emotion Classification
dataset:
type: tess-crema-d
name: Combined TESS and CREMA-D
metrics:
- type: accuracy
value: 0.96
name: Test Accuracy
- type: mse
value: 0.094
name: Arousal-Valence MSE
---
# Audio Emotion Classification with Arousal-Valence Prediction
This model performs audio emotion classification while simultaneously predicting continuous arousal and valence values. It combines multiple audio features (Wav2Vec2, MFCC, and prosodic features) to achieve robust emotion recognition.
## Model Description
- **Task**: Audio emotion classification with arousal-valence prediction
- **Architecture**: Dual-branch neural network (emotion + arousal-valence)
- **Features**: Wav2Vec2 (768) + MFCC (13) + Prosodic (6) = 787 dimensions
- **Emotions**: angry, disgust, fear, happy, neutral, sad
- **Performance**: ~96% accuracy on test set, MSE ~0.094 for arousal-valence
## Quick Start
### Using the Pipeline (Recommended)
```python
from pipeline_emotion_av import pipeline
# Create pipeline
emotion_pipeline = pipeline(
"audio-emotion-classification",
model="pricklypearhealth/emotion-av-model"
)
# Process audio
result = emotion_pipeline("path/to/audio.wav", return_all_scores=True)
print(result)
```
### Direct Model Usage
```python
from modeling_emotion_av import EmotionAVModel
from feature_extraction_emotion_av import EmotionAVFeatureExtractor
# Load model and feature extractor
model = EmotionAVModel.from_pretrained("pricklypearhealth/emotion-av-model")
feature_extractor = EmotionAVFeatureExtractor.from_pretrained("pricklypearhealth/emotion-av-model")
# Process audio file
features = feature_extractor.from_file("path/to/audio.wav", return_tensors="pt")
result = model.predict_emotion(features["input_features"])
print(f"Emotion: {result['emotion']}")
print(f"Confidence: {result['confidence']:.4f}")
print(f"Arousal: {result['arousal']:.4f}")
print(f"Valence: {result['valence']:.4f}")
```
## Features
### Multi-Modal Feature Extraction
- **Wav2Vec2**: Pre-trained transformer features from facebook/wav2vec2-base-960h
- **MFCC**: 13 Mel-frequency cepstral coefficients
- **Prosodic**: Pitch (mean/std), energy, zero-crossing rate, jitter, shimmer
### Dual Prediction Output
- **Discrete Emotions**: 6-class classification (angry, disgust, fear, happy, neutral, sad)
- **Continuous Values**: Arousal (-1 to +1) and Valence (-1 to +1) scores
### Flexible Input Formats
- Audio file paths (WAV, MP3, etc.)
- Raw audio arrays (numpy)
- List of audio samples
- Batch processing support
## Training Details
- **Datasets**: TESS + CREMA-D (balanced via oversampling)
- **Features**: Wav2Vec2 + MFCC + Prosodic (787 total dimensions)
- **Architecture**: Dual-branch neural network with BatchNorm and Dropout
- **Training**: 30 epochs with early stopping, ReduceLROnPlateau scheduler
## Model Architecture
```
Input Audio (16kHz)
β
Feature Extraction:
βββ Wav2Vec2 (768 features)
βββ MFCC (13 features)
βββ Prosodic (6 features)
β
Combined Features (787 dims)
β
Dual Branch Network:
βββ Emotion Branch β 6-class Classification
βββ AV Branch β 2D Regression (Arousal, Valence)
```
## API Usage
### Inference API
This model supports the Hugging Face Inference API. You can use it directly:
```python
import requests
import base64
# Encode audio file
with open("audio.wav", "rb") as f:
audio_bytes = f.read()
audio_b64 = base64.b64encode(audio_bytes).decode()
# Make API request
response = requests.post(
"https://api-inference.huggingface.co/models/pricklypearhealth/emotion-av-model",
headers={"Authorization": "Bearer YOUR_HF_TOKEN"},
json={"inputs": audio_b64}
)
result = response.json()
print(result)
```
### Expected Response Format
```json
[
{
"label": "happy",
"score": 0.8542,
"arousal": 0.7234,
"valence": 0.9123,
"all_scores": [
{ "label": "happy", "score": 0.8542 },
{ "label": "neutral", "score": 0.0892 },
{ "label": "sad", "score": 0.0456 }
]
}
]
```
### Using Inference Endpoints
For production use, you can deploy this model on Hugging Face Inference Endpoints:
```python
import requests
import base64
# Encode audio file
with open("audio.wav", "rb") as f:
audio_bytes = f.read()
audio_b64 = base64.b64encode(audio_bytes).decode()
# Make request to your Inference Endpoint
response = requests.post(
"https://YOUR_ENDPOINT_URL.endpoints.huggingface.cloud",
headers={
"Authorization": "Bearer YOUR_HF_TOKEN",
"Content-Type": "application/json",
},
json={
"inputs": audio_b64,
"parameters": {
"return_all_scores": True,
"sampling_rate": 16000
}
}
)
result = response.json()
print(result)
```
## Citation
If you use this model, please cite:
```bibtex
@misc{emotion-av-model,
title={Audio Emotion Classification with Arousal-Valence Prediction},
author={Your Name},
year={2024},
url={https://huggingface.co/pricklypearhealth/emotion-av-model}
}
```
|