firdhokk commited on
Commit
e10f24a
Β·
verified Β·
1 Parent(s): 3e83404

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +124 -42
README.md CHANGED
@@ -17,47 +17,74 @@ model-index:
17
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
18
  should probably proofread and complete it, then remove this comment. -->
19
 
20
- # speech-emotion-recognition-with-openai-whisper-large-v3
21
-
22
- This model is a fine-tuned version of [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3) on the [RAVDESS](https://zenodo.org/records/1188976#.XsAXemgzaUk), [SAVEE](https://www.kaggle.com/datasets/ejlok1/surrey-audiovisual-expressed-emotion-savee/data), [TESS](https://tspace.library.utoronto.ca/handle/1807/24487), and [URDU](https://www.kaggle.com/datasets/bitlord/urdu-language-speech-dataset) dataset.
23
- It achieves the following results on the evaluation set:
24
- - Loss: 0.5008
25
- - Accuracy: 0.9199
26
- - Precision: 0.9230
27
- - Recall: 0.9199
28
- - F1: 0.9198
29
-
30
- ## Model description
31
-
32
- More information needed
33
-
34
- ## Intended uses & limitations
35
-
36
- More information needed
37
-
38
- ## Training and evaluation data
39
-
40
- More information needed
41
-
42
- ## Training procedure
43
-
44
- ### Training hyperparameters
45
-
46
- The following hyperparameters were used during training:
47
- - learning_rate: 5e-05
48
- - train_batch_size: 2
49
- - eval_batch_size: 2
50
- - seed: 42
51
- - gradient_accumulation_steps: 5
52
- - total_train_batch_size: 10
53
- - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
54
- - lr_scheduler_type: linear
55
- - lr_scheduler_warmup_ratio: 0.1
56
- - num_epochs: 25
57
- - mixed_precision_training: Native AMP
58
-
59
- ### Training results
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  | Training Loss | Epoch | Step | Validation Loss | Accuracy | Precision | Recall | F1 |
62
  |:-------------:|:-------:|:----:|:---------------:|:--------:|:---------:|:------:|:------:|
63
  | 0.4948 | 0.9995 | 394 | 0.4911 | 0.8286 | 0.8449 | 0.8286 | 0.8302 |
@@ -73,8 +100,63 @@ The following hyperparameters were used during training:
73
  | 0.0026 | 10.9995 | 4336 | 0.8334 | 0.8773 | 0.8949 | 0.8773 | 0.8770 |
74
 
75
 
76
- ### Framework versions
77
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  - Transformers 4.44.2
79
  - Pytorch 2.4.1+cu121
80
  - Datasets 3.0.0
 
17
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
18
  should probably proofread and complete it, then remove this comment. -->
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # 🎧 **Speech Emotion Recognition with Whisper**
22
+ This project leverages the **Whisper** model to recognize emotions in speech. The goal is to classify audio recordings into different emotional categories, such as **Happy**, **Sad**, **Surprised**, and etc.
23
+
24
+
25
+ ## πŸ—‚ **Dataset**
26
+ The dataset used for training and evaluation is sourced from multiple datasets, including:
27
+ - [RAVDESS](https://zenodo.org/records/1188976#.XsAXemgzaUk)
28
+ - [SAVEE](https://www.kaggle.com/datasets/ejlok1/surrey-audiovisual-expressed-emotion-savee/data)
29
+ - [TESS](https://tspace.library.utoronto.ca/handle/1807/24487)
30
+ - [URDU](https://www.kaggle.com/datasets/bitlord/urdu-language-speech-dataset)
31
+
32
+ The dataset contains recordings labeled with various emotions. Below is the distribution of the emotions in the dataset:
33
+ | **Emotion** | **Count** |
34
+ |-------------|-----------|
35
+ | sad | 752 |
36
+ | happy | 752 |
37
+ | angry | 752 |
38
+ | neutral | 716 |
39
+ | disgust | 652 |
40
+ | fearful | 652 |
41
+ | surprised | 652 |
42
+ | calm | 192 |
43
+
44
+ This distribution reflects the balance of emotions in the dataset, with some emotions having more samples than others. Excluded the "calm" emotion during training due to its underrepresentation.
45
+
46
+
47
+ ## 🎀 **Preprocessing**
48
+ - **Audio Loading**: Using **Librosa** to load the audio files and convert them to numpy arrays.
49
+ - **Feature Extraction**: The audio data is processed using the **Whisper Feature Extractor**, which standardizes and normalizes the audio features for input to the model.
50
+
51
+
52
+ ## πŸ”§ **Model**
53
+ The model used is the **Wav2Vec2 Large XLR-53** model, fine-tuned for **audio classification** tasks:
54
+ - **Model**: [openai/whisper-large-v3](https://huggingface.co/openai/whisper-large-v3)
55
+ - **Output**: Emotion labels (`Angry', 'Disgust', 'Fearful', 'Happy', 'Neutral', 'Sad', 'Surprised'`)
56
+ I map the emotion labels to numeric IDs and use them for model training and evaluation.
57
+
58
+
59
+ ## βš™οΈ **Training**
60
+ The model is trained with the following parameters:
61
+ - **Learning Rate**: `5e-05`
62
+ - **Train Batch Size**: `2`
63
+ - **Eval Batch Size**: `2`
64
+ - **Random Seed**: `42`
65
+ - **Gradient Accumulation Steps**: `5`
66
+ - **Total Train Batch Size**: `10` (effective batch size after gradient accumulation)
67
+ - **Optimizer**: **Adam** with parameters: `betas=(0.9, 0.999)` and `epsilon=1e-08`
68
+ - **Learning Rate Scheduler**: `linear`
69
+ - **Warmup Ratio for LR Scheduler**: `0.1`
70
+ - **Number of Epochs**: `25`
71
+ - **Mixed Precision Training**: Native AMP (Automatic Mixed Precision)
72
+ These parameters ensure efficient model training and stability, especially when dealing with large datasets and deep models like **Whisper**.
73
+ The training utilizes **Wandb** for experiment tracking and monitoring.
74
+
75
+
76
+ ## πŸ“Š **Metrics**
77
+ The following evaluation metrics were obtained after training the model:
78
+ - **Loss**: `0.5008`
79
+ - **Accuracy**: `0.9199`
80
+ - **Precision**: `0.9230`
81
+ - **Recall**: `0.9199`
82
+ - **F1 Score**: `0.9198`
83
+ These metrics demonstrate the model's performance on the speech emotion recognition task. The high values for accuracy, precision, recall, and F1 score indicate that the model is effectively identifying emotional states from speech data.
84
+
85
+
86
+ ## πŸ§ͺ **Results**
87
+ After training, the model is evaluated on the test dataset, and the results are monitored using **Wandb** in this [Link](https://wandb.ai/firdhoworking-sepuluh-nopember-institute-of-technology/speech-emotion-recognition-with-whisper?nw=nwuserfirdhoworking).
88
  | Training Loss | Epoch | Step | Validation Loss | Accuracy | Precision | Recall | F1 |
89
  |:-------------:|:-------:|:----:|:---------------:|:--------:|:---------:|:------:|:------:|
90
  | 0.4948 | 0.9995 | 394 | 0.4911 | 0.8286 | 0.8449 | 0.8286 | 0.8302 |
 
100
  | 0.0026 | 10.9995 | 4336 | 0.8334 | 0.8773 | 0.8949 | 0.8773 | 0.8770 |
101
 
102
 
103
+ ## πŸš€ **How to Use**
104
+ ```python
105
+ from transformers import AutoModelForAudioClassification, AutoFeatureExtractor
106
+ import librosa
107
+ import torch
108
+ import numpy as np
109
+
110
+ model_id = "firdhokk/speech-emotion-recognition-with-openai-whisper-large-v3"
111
+ model = AutoModelForAudioClassification.from_pretrained(model_id)
112
+
113
+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_id, do_normalize=True)
114
+ id2label = model.config.id2label
115
+ ```
116
+ ```python
117
+ def preprocess_audio(audio_path, feature_extractor, max_duration=30.0):
118
+ audio_array, sampling_rate = librosa.load(audio_path, sr=feature_extractor.sampling_rate)
119
+
120
+ max_length = int(feature_extractor.sampling_rate * max_duration)
121
+ if len(audio_array) > max_length:
122
+ audio_array = audio_array[:max_length]
123
+ else:
124
+ audio_array = np.pad(audio_array, (0, max_length - len(audio_array)))
125
+
126
+ inputs = feature_extractor(
127
+ audio_array,
128
+ sampling_rate=feature_extractor.sampling_rate,
129
+ max_length=max_length,
130
+ truncation=True,
131
+ return_tensors="pt",
132
+ )
133
+ return inputs
134
+ ```
135
+ ```python
136
+ def predict_emotion(audio_path, model, feature_extractor, id2label, max_duration=30.0):
137
+ inputs = preprocess_audio(audio_path, feature_extractor, max_duration)
138
+
139
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
140
+ model = model.to(device)
141
+ inputs = {key: value.to(device) for key, value in inputs.items()}
142
+
143
+ with torch.no_grad():
144
+ outputs = model(**inputs)
145
+
146
+ logits = outputs.logits
147
+ predicted_id = torch.argmax(logits, dim=-1).item()
148
+ predicted_label = id2label[predicted_id]
149
+
150
+ return predicted_label
151
+ ```
152
+ ```python
153
+ audio_path = "/content/drive/MyDrive/Audio/Speech_URDU/Happy/SM5_F4_H058.wav"
154
+
155
+ predicted_emotion = predict_emotion(audio_path, model, feature_extractor, id2label)
156
+ print(f"Predicted Emotion: {predicted_emotion}")
157
+ ```
158
+
159
+ ## 🎯 Framework versions
160
  - Transformers 4.44.2
161
  - Pytorch 2.4.1+cu121
162
  - Datasets 3.0.0