wtfkedar commited on
Commit
5fc3881
·
verified ·
1 Parent(s): 0c2d3a6
.gitattributes CHANGED
@@ -1,35 +1 @@
1
- *.7z filter=lfs diff=lfs merge=lfs -text
2
- *.arrow filter=lfs diff=lfs merge=lfs -text
3
- *.bin filter=lfs diff=lfs merge=lfs -text
4
- *.bz2 filter=lfs diff=lfs merge=lfs -text
5
- *.ckpt filter=lfs diff=lfs merge=lfs -text
6
- *.ftz filter=lfs diff=lfs merge=lfs -text
7
- *.gz filter=lfs diff=lfs merge=lfs -text
8
- *.h5 filter=lfs diff=lfs merge=lfs -text
9
- *.joblib filter=lfs diff=lfs merge=lfs -text
10
- *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
- *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
- *.model filter=lfs diff=lfs merge=lfs -text
13
- *.msgpack filter=lfs diff=lfs merge=lfs -text
14
- *.npy filter=lfs diff=lfs merge=lfs -text
15
- *.npz filter=lfs diff=lfs merge=lfs -text
16
- *.onnx filter=lfs diff=lfs merge=lfs -text
17
- *.ot filter=lfs diff=lfs merge=lfs -text
18
- *.parquet filter=lfs diff=lfs merge=lfs -text
19
- *.pb filter=lfs diff=lfs merge=lfs -text
20
- *.pickle filter=lfs diff=lfs merge=lfs -text
21
- *.pkl filter=lfs diff=lfs merge=lfs -text
22
- *.pt filter=lfs diff=lfs merge=lfs -text
23
- *.pth filter=lfs diff=lfs merge=lfs -text
24
- *.rar filter=lfs diff=lfs merge=lfs -text
25
- *.safetensors filter=lfs diff=lfs merge=lfs -text
26
- saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
- *.tar.* filter=lfs diff=lfs merge=lfs -text
28
- *.tar filter=lfs diff=lfs merge=lfs -text
29
- *.tflite filter=lfs diff=lfs merge=lfs -text
30
- *.tgz filter=lfs diff=lfs merge=lfs -text
31
- *.wasm filter=lfs diff=lfs merge=lfs -text
32
- *.xz filter=lfs diff=lfs merge=lfs -text
33
- *.zip filter=lfs diff=lfs merge=lfs -text
34
- *.zst filter=lfs diff=lfs merge=lfs -text
35
- *tfevents* filter=lfs diff=lfs merge=lfs -text
 
1
+ *.bin filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,3 +1,47 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ HEAD
2
+ ---
3
+ license: mit
4
+ ---
5
+
6
+ ---
7
+ language:
8
+ - multilingual
9
+ license: apache-2.0
10
+ tags:
11
+ - voice
12
+ - classification
13
+ - vocalization
14
+ - speech
15
+ - audio
16
+ datasets:
17
+ - NonverbalVocalization
18
+ widget:
19
+ - src: >-
20
+ https://huggingface.co/padmalcom/wav2vec2-large-nonverbalvocalization-classification/resolve/main/test.wav
21
+ example_title: Sample 1
22
+ pipeline_tag: audio-classification
23
+ metrics:
24
+ - accuracy
25
+ ---
26
+ This language indendent wav2vec2 classification model is based on [this dataset](https://github.com/deeplyinc/Nonverbal-Vocalization-Dataset).
27
+
28
+ Sound classes are:
29
+ - teeth-chattering
30
+ - teeth-grinding
31
+ - tongue-clicking
32
+ - nose-blowing
33
+ - coughing
34
+ - yawning
35
+ - throat clearing
36
+ - sighing
37
+ - lip-popping
38
+ - lip-smacking
39
+ - panting
40
+ - crying
41
+ - laughing
42
+ - sneezing
43
+ - moaning
44
+ - screaming
45
+
46
+ *inference.py* shows, how the model can be used.
47
+ 18e5a42 (Initial commit of Nonverbal-AudioCLwav2vec2 model)
config.json ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "facebook/wav2vec2-large-960h-lv60-self",
3
+ "activation_dropout": 0.1,
4
+ "adapter_kernel_size": 3,
5
+ "adapter_stride": 2,
6
+ "add_adapter": false,
7
+ "apply_spec_augment": true,
8
+ "architectures": [
9
+ "Wav2Vec2ForSpeechClassification"
10
+ ],
11
+ "attention_dropout": 0.1,
12
+ "bos_token_id": 1,
13
+ "classifier_proj_size": 256,
14
+ "codevector_dim": 256,
15
+ "contrastive_logits_temperature": 0.1,
16
+ "conv_bias": true,
17
+ "conv_dim": [
18
+ 512,
19
+ 512,
20
+ 512,
21
+ 512,
22
+ 512,
23
+ 512,
24
+ 512
25
+ ],
26
+ "conv_kernel": [
27
+ 10,
28
+ 3,
29
+ 3,
30
+ 3,
31
+ 3,
32
+ 2,
33
+ 2
34
+ ],
35
+ "conv_stride": [
36
+ 5,
37
+ 2,
38
+ 2,
39
+ 2,
40
+ 2,
41
+ 2,
42
+ 2
43
+ ],
44
+ "ctc_loss_reduction": "sum",
45
+ "ctc_zero_infinity": false,
46
+ "diversity_loss_weight": 0.1,
47
+ "do_stable_layer_norm": true,
48
+ "eos_token_id": 2,
49
+ "feat_extract_activation": "gelu",
50
+ "feat_extract_dropout": 0.0,
51
+ "feat_extract_norm": "layer",
52
+ "feat_proj_dropout": 0.1,
53
+ "feat_quantizer_dropout": 0.0,
54
+ "final_dropout": 0.1,
55
+ "finetuning_task": "wav2vec2_clf",
56
+ "gradient_checkpointing": false,
57
+ "hidden_act": "gelu",
58
+ "hidden_dropout": 0.1,
59
+ "hidden_dropout_prob": 0.1,
60
+ "hidden_size": 1024,
61
+ "id2label": {
62
+ "0": "teeth-chattering",
63
+ "1": "teeth-grinding",
64
+ "2": "tongue-clicking",
65
+ "3": "nose-blowing",
66
+ "4": "coughing",
67
+ "5": "yawning",
68
+ "6": "throat-clearing",
69
+ "7": "sighing",
70
+ "8": "lip-popping",
71
+ "9": "lip-smacking",
72
+ "10": "panting",
73
+ "11": "crying",
74
+ "12": "laughing",
75
+ "13": "sneezing",
76
+ "14": "moaning",
77
+ "15": "screaming"
78
+ },
79
+ "initializer_range": 0.02,
80
+ "intermediate_size": 4096,
81
+ "label2id": {
82
+ "coughing": 4,
83
+ "crying": 11,
84
+ "laughing": 12,
85
+ "lip-popping": 8,
86
+ "lip-smacking": 9,
87
+ "moaning": 14,
88
+ "nose-blowing": 3,
89
+ "panting": 10,
90
+ "screaming": 15,
91
+ "sighing": 7,
92
+ "sneezing": 13,
93
+ "teeth-chattering": 0,
94
+ "teeth-grinding": 1,
95
+ "throat-clearing": 6,
96
+ "tongue-clicking": 2,
97
+ "yawning": 5
98
+ },
99
+ "layer_norm_eps": 1e-05,
100
+ "layerdrop": 0.1,
101
+ "mask_feature_length": 10,
102
+ "mask_feature_min_masks": 0,
103
+ "mask_feature_prob": 0.0,
104
+ "mask_time_length": 10,
105
+ "mask_time_min_masks": 2,
106
+ "mask_time_prob": 0.05,
107
+ "model_type": "wav2vec2",
108
+ "num_adapter_layers": 3,
109
+ "num_attention_heads": 16,
110
+ "num_codevector_groups": 2,
111
+ "num_codevectors_per_group": 320,
112
+ "num_conv_pos_embedding_groups": 16,
113
+ "num_conv_pos_embeddings": 128,
114
+ "num_feat_extract_layers": 7,
115
+ "num_hidden_layers": 24,
116
+ "num_negatives": 100,
117
+ "output_hidden_size": 1024,
118
+ "pad_token_id": 0,
119
+ "pooling_mode": "mean",
120
+ "problem_type": "single_label_classification",
121
+ "proj_codevector_dim": 256,
122
+ "tdnn_dilation": [
123
+ 1,
124
+ 2,
125
+ 3,
126
+ 1,
127
+ 1
128
+ ],
129
+ "tdnn_dim": [
130
+ 512,
131
+ 512,
132
+ 512,
133
+ 512,
134
+ 1500
135
+ ],
136
+ "tdnn_kernel": [
137
+ 5,
138
+ 3,
139
+ 3,
140
+ 1,
141
+ 1
142
+ ],
143
+ "torch_dtype": "float32",
144
+ "transformers_version": "4.25.1",
145
+ "use_weighted_layer_sum": false,
146
+ "vocab_size": 32,
147
+ "xvector_output_dim": 512
148
+ }
inference.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn.functional as F
3
+ import torchaudio
4
+ from transformers import AutoConfig, Wav2Vec2Processor
5
+
6
+ from Wav2Vec2ForSpeechClassification import Wav2Vec2ForSpeechClassification
7
+
8
+ MY_MODEL = "padmalcom/wav2vec2-large-nonverbalvocalization-classification"
9
+
10
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11
+ config = AutoConfig.from_pretrained(MY_MODEL)
12
+ processor = Wav2Vec2Processor.from_pretrained(MY_MODEL)
13
+ sampling_rate = processor.feature_extractor.sampling_rate
14
+ model = Wav2Vec2ForSpeechClassification.from_pretrained(MY_MODEL).to(device)
15
+
16
+ def speech_file_to_array_fn(path, sampling_rate):
17
+ speech_array, _sampling_rate = torchaudio.load(path)
18
+ resampler = torchaudio.transforms.Resample(_sampling_rate)
19
+ speech = resampler(speech_array).squeeze().numpy()
20
+ return speech
21
+
22
+
23
+ def predict(path, sampling_rate):
24
+ speech = speech_file_to_array_fn(path, sampling_rate)
25
+ features = processor(speech, sampling_rate=sampling_rate, return_tensors="pt", padding=True)
26
+
27
+ input_values = features.input_values.to(device)
28
+ attention_mask = features.attention_mask.to(device)
29
+
30
+ with torch.no_grad():
31
+ logits = model(input_values, attention_mask=attention_mask).logits
32
+
33
+ scores = F.softmax(logits, dim=1).detach().cpu().numpy()[0]
34
+ outputs = [{"Vocalization": config.id2label[i], "Score": f"{round(score * 100, 3):.1f}%"} for i, score in enumerate(scores)]
35
+ return outputs
36
+
37
+ res = predict("test.wav", 16000)
38
+ max = max(res, key=lambda x: x['Score'])
39
+ print("Expected lip popping:", max)
preprocessor_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "feature_extractor_type": "Wav2Vec2FeatureExtractor",
4
+ "feature_size": 1,
5
+ "padding_side": "right",
6
+ "padding_value": 0.0,
7
+ "return_attention_mask": true,
8
+ "sampling_rate": 16000
9
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56a09bf8bb4a628bdf32d6d96d37e15c9b3f490bda8f48c08441f5cb258e28e9
3
+ size 1266163373
special_tokens_map.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "eos_token": "</s>",
4
+ "pad_token": "<pad>",
5
+ "unk_token": "<unk>"
6
+ }
test.wav ADDED
Binary file (123 kB). View file
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "do_lower_case": false,
4
+ "do_normalize": true,
5
+ "eos_token": "</s>",
6
+ "model_max_length": 1000000000000000019884624838656,
7
+ "name_or_path": "facebook/wav2vec2-large-960h-lv60-self",
8
+ "pad_token": "<pad>",
9
+ "replace_word_delimiter_char": " ",
10
+ "return_attention_mask": true,
11
+ "special_tokens_map_file": "C:\\Users\\admin/.cache\\huggingface\\hub\\models--facebook--wav2vec2-large-960h-lv60-self\\snapshots\\54074b1c16f4de6a5ad59affb4caa8f2ea03a119\\special_tokens_map.json",
12
+ "tokenizer_class": "Wav2Vec2CTCTokenizer",
13
+ "unk_token": "<unk>",
14
+ "word_delimiter_token": "|"
15
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b19e5d57926cf4a2a3707f9b4f4871fcffe80b7405debaf0f3eb903f056575dd
3
+ size 3375
vocab.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "'": 27,
3
+ "</s>": 2,
4
+ "<pad>": 0,
5
+ "<s>": 1,
6
+ "<unk>": 3,
7
+ "A": 7,
8
+ "B": 24,
9
+ "C": 19,
10
+ "D": 14,
11
+ "E": 5,
12
+ "F": 20,
13
+ "G": 21,
14
+ "H": 11,
15
+ "I": 10,
16
+ "J": 29,
17
+ "K": 26,
18
+ "L": 15,
19
+ "M": 17,
20
+ "N": 9,
21
+ "O": 8,
22
+ "P": 23,
23
+ "Q": 30,
24
+ "R": 13,
25
+ "S": 12,
26
+ "T": 6,
27
+ "U": 16,
28
+ "V": 25,
29
+ "W": 18,
30
+ "X": 28,
31
+ "Y": 22,
32
+ "Z": 31,
33
+ "|": 4
34
+ }