r-f commited on
Commit
2c59b3f
·
verified ·
1 Parent(s): e7ae5db

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +30 -6
README.md CHANGED
@@ -22,12 +22,36 @@ emotions = ['angry' 'disgust' 'fear' 'happy' 'neutral' 'sad' 'surprise']
22
  It achieves the following results on the evaluation set:
23
  - Loss: 0.104075
24
  - Accuracy: 0.97463
25
- ## Model description
26
- More information needed
27
- ## Intended uses & limitations
28
- More information needed
29
- ## Training and evaluation data
30
- More information needed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  ## Training procedure
32
  ### Training hyperparameters
33
  The following hyperparameters were used during training:
 
22
  It achieves the following results on the evaluation set:
23
  - Loss: 0.104075
24
  - Accuracy: 0.97463
25
+
26
+ ## Model Usage
27
+ ```bash
28
+ pip install transformers librosa torch
29
+ ```
30
+ ```python
31
+ from transformers import *
32
+ import librosa
33
+ import torch
34
+
35
+ feature_extractor = Wav2Vec2FeatureExtractor.from_pretrained("r-f/wav2vec-english-speech-emotion-recognition")
36
+ model = Wav2Vec2ForCTC.from_pretrained("r-f/wav2vec-english-speech-emotion-recognition")
37
+
38
+ def predict_emotion(audio_path):
39
+ audio, rate = librosa.load(audio_path, sr=16000)
40
+ inputs = feature_extractor(audio, sampling_rate=rate, return_tensors="pt", padding=True)
41
+
42
+ with torch.no_grad():
43
+ outputs = model(inputs.input_values)
44
+ predictions = torch.nn.functional.softmax(outputs.logits.mean(dim=1), dim=-1) # Average over sequence length
45
+ predicted_label = torch.argmax(predictions, dim=-1)
46
+ emotion = model.config.id2label[predicted_label.item()]
47
+ return emotion
48
+
49
+ emotion = predict_emotion("example_audio.wav")
50
+ print(f"Predicted emotion: {emotion}")
51
+ >> Predicted emotion: angry
52
+ ```
53
+
54
+
55
  ## Training procedure
56
  ### Training hyperparameters
57
  The following hyperparameters were used during training: