Julien Simon
commited on
Commit
•
66ede47
1
Parent(s):
f86622c
Update README.md
Browse files
README.md
CHANGED
@@ -50,6 +50,37 @@ The repository includes sample files that I recorded (WAV, 16Khz sampling rate,
|
|
50 |
[{'score': 0.5276530981063843, 'label': 'marvin'}, {'score': 0.04645705968141556, 'label': 'down'}, {'score': 0.038583893328905106, 'label': 'backward'}, {'score': 0.03578080236911774, 'label': 'wow'}, {'score': 0.03178196772933006, 'label': 'bird'}]
|
51 |
```
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
### Training and evaluation data
|
54 |
|
55 |
- subset: v0.02
|
|
|
50 |
[{'score': 0.5276530981063843, 'label': 'marvin'}, {'score': 0.04645705968141556, 'label': 'down'}, {'score': 0.038583893328905106, 'label': 'backward'}, {'score': 0.03578080236911774, 'label': 'wow'}, {'score': 0.03178196772933006, 'label': 'bird'}]
|
51 |
```
|
52 |
|
53 |
+
You can also use with the ```Auto```API:
|
54 |
+
|
55 |
+
```
|
56 |
+
>>> import torch, librosa
|
57 |
+
>>> from transformers import AutoModelForAudioClassification, Wav2Vec2FeatureExtractor
|
58 |
+
>>> feature_extractor = Wav2Vec2FeatureExtractor(feature_size=1, sampling_rate=16000, padding_value=0.0, do_normalize=True, return_attention_mask=False)
|
59 |
+
>>> model = AutoModelForAudioClassification.from_pretrained("juliensimon/wav2vec2-conformer-rel-pos-large-finetuned-speech-commands")
|
60 |
+
>>> audio, rate = librosa.load("up16k.wav", sr = 16000)
|
61 |
+
>>> inputs = feature_extractor(audio, sampling_rate=16000, return_tensors = "pt")
|
62 |
+
>>> logits = model(inputs['input_values'])
|
63 |
+
>>> logits
|
64 |
+
SequenceClassifierOutput(loss=None, logits=tensor([[-0.4635, -1.0112, 4.7935, 0.8528, 1.6265, 0.6456, 1.5423, 2.0132,
|
65 |
+
1.6103, 0.5847, -2.2526, 0.8839, 0.8163, -1.5655, -1.4160, -0.4196,
|
66 |
+
-0.1097, -1.8827, 0.6609, -0.2022, 0.0971, -0.6205, 0.4492, 0.0926,
|
67 |
+
-2.4848, 0.2630, -0.4584, -2.4327, -1.1654, 0.3897, -0.3374, -1.2418,
|
68 |
+
-0.1045, 0.2827, -1.5667, -0.0963]], grad_fn=<AddmmBackward0>), hidden_states=None, attentions=None)
|
69 |
+
>>> classes = torch.softmax(logits.logits, dim = -1)
|
70 |
+
>>> classes
|
71 |
+
tensor([[3.6522e-03, 2.1118e-03, 7.0082e-01, 1.3621e-02, 2.9527e-02, 1.1071e-02,
|
72 |
+
2.7143e-02, 4.3466e-02, 2.9051e-02, 1.0417e-02, 6.1027e-04, 1.4051e-02,
|
73 |
+
1.3132e-02, 1.2132e-03, 1.4089e-03, 3.8160e-03, 5.2022e-03, 8.8345e-04,
|
74 |
+
1.1242e-02, 4.7424e-03, 6.3974e-03, 3.1215e-03, 9.0975e-03, 6.3689e-03,
|
75 |
+
4.8384e-04, 7.5519e-03, 3.6707e-03, 5.0970e-04, 1.8101e-03, 8.5720e-03,
|
76 |
+
4.1427e-03, 1.6769e-03, 5.2292e-03, 7.7021e-03, 1.2117e-03, 5.2723e-03]],
|
77 |
+
grad_fn=<SoftmaxBackward0>)
|
78 |
+
>>> top_class = torch.argmax(logits.logits, dim = -1)
|
79 |
+
>>> top_class = top_class.detach().numpy()[0]
|
80 |
+
>>> model.config.id2label[top_class]
|
81 |
+
'up'
|
82 |
+
```
|
83 |
+
|
84 |
### Training and evaluation data
|
85 |
|
86 |
- subset: v0.02
|