techsword commited on
Commit
de16083
·
verified ·
1 Parent(s): 52f2b84

Upload Wav2Vec2ForMultiHeadMultiLabelClassification

Browse files
README.md ADDED
@@ -0,0 +1,199 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ tags: []
4
+ ---
5
+
6
+ # Model Card for Model ID
7
+
8
+ <!-- Provide a quick summary of what the model is/does. -->
9
+
10
+
11
+
12
+ ## Model Details
13
+
14
+ ### Model Description
15
+
16
+ <!-- Provide a longer summary of what this model is. -->
17
+
18
+ This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
+
20
+ - **Developed by:** [More Information Needed]
21
+ - **Funded by [optional]:** [More Information Needed]
22
+ - **Shared by [optional]:** [More Information Needed]
23
+ - **Model type:** [More Information Needed]
24
+ - **Language(s) (NLP):** [More Information Needed]
25
+ - **License:** [More Information Needed]
26
+ - **Finetuned from model [optional]:** [More Information Needed]
27
+
28
+ ### Model Sources [optional]
29
+
30
+ <!-- Provide the basic links for the model. -->
31
+
32
+ - **Repository:** [More Information Needed]
33
+ - **Paper [optional]:** [More Information Needed]
34
+ - **Demo [optional]:** [More Information Needed]
35
+
36
+ ## Uses
37
+
38
+ <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
+
40
+ ### Direct Use
41
+
42
+ <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
+
44
+ [More Information Needed]
45
+
46
+ ### Downstream Use [optional]
47
+
48
+ <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
+
50
+ [More Information Needed]
51
+
52
+ ### Out-of-Scope Use
53
+
54
+ <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
+
56
+ [More Information Needed]
57
+
58
+ ## Bias, Risks, and Limitations
59
+
60
+ <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
+
62
+ [More Information Needed]
63
+
64
+ ### Recommendations
65
+
66
+ <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
+
68
+ Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
+
70
+ ## How to Get Started with the Model
71
+
72
+ Use the code below to get started with the model.
73
+
74
+ [More Information Needed]
75
+
76
+ ## Training Details
77
+
78
+ ### Training Data
79
+
80
+ <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
+
82
+ [More Information Needed]
83
+
84
+ ### Training Procedure
85
+
86
+ <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
+
88
+ #### Preprocessing [optional]
89
+
90
+ [More Information Needed]
91
+
92
+
93
+ #### Training Hyperparameters
94
+
95
+ - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
+
97
+ #### Speeds, Sizes, Times [optional]
98
+
99
+ <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
+
101
+ [More Information Needed]
102
+
103
+ ## Evaluation
104
+
105
+ <!-- This section describes the evaluation protocols and provides the results. -->
106
+
107
+ ### Testing Data, Factors & Metrics
108
+
109
+ #### Testing Data
110
+
111
+ <!-- This should link to a Dataset Card if possible. -->
112
+
113
+ [More Information Needed]
114
+
115
+ #### Factors
116
+
117
+ <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
+
119
+ [More Information Needed]
120
+
121
+ #### Metrics
122
+
123
+ <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
+
125
+ [More Information Needed]
126
+
127
+ ### Results
128
+
129
+ [More Information Needed]
130
+
131
+ #### Summary
132
+
133
+
134
+
135
+ ## Model Examination [optional]
136
+
137
+ <!-- Relevant interpretability work for the model goes here -->
138
+
139
+ [More Information Needed]
140
+
141
+ ## Environmental Impact
142
+
143
+ <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
+
145
+ Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
+
147
+ - **Hardware Type:** [More Information Needed]
148
+ - **Hours used:** [More Information Needed]
149
+ - **Cloud Provider:** [More Information Needed]
150
+ - **Compute Region:** [More Information Needed]
151
+ - **Carbon Emitted:** [More Information Needed]
152
+
153
+ ## Technical Specifications [optional]
154
+
155
+ ### Model Architecture and Objective
156
+
157
+ [More Information Needed]
158
+
159
+ ### Compute Infrastructure
160
+
161
+ [More Information Needed]
162
+
163
+ #### Hardware
164
+
165
+ [More Information Needed]
166
+
167
+ #### Software
168
+
169
+ [More Information Needed]
170
+
171
+ ## Citation [optional]
172
+
173
+ <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
+
175
+ **BibTeX:**
176
+
177
+ [More Information Needed]
178
+
179
+ **APA:**
180
+
181
+ [More Information Needed]
182
+
183
+ ## Glossary [optional]
184
+
185
+ <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
+
187
+ [More Information Needed]
188
+
189
+ ## More Information [optional]
190
+
191
+ [More Information Needed]
192
+
193
+ ## Model Card Authors [optional]
194
+
195
+ [More Information Needed]
196
+
197
+ ## Model Card Contact
198
+
199
+ [More Information Needed]
config.json ADDED
@@ -0,0 +1,176 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation_dropout": 0.0,
3
+ "adapter_attn_dim": null,
4
+ "adapter_kernel_size": 3,
5
+ "adapter_stride": 2,
6
+ "add_adapter": false,
7
+ "apply_spec_augment": true,
8
+ "architectures": [
9
+ "Wav2Vec2ForMultiHeadMultiLabelClassification"
10
+ ],
11
+ "attention_dropout": 0.1,
12
+ "auto_map": {
13
+ "AutoConfig": "configuration_wav2vec2multihead.Wav2Vec2MultiHeadConfig",
14
+ "AutoModelForSequenceClassification": "modeling_wav2vec2multihead.Wav2Vec2ForMultiHeadMultiLabelClassification"
15
+ },
16
+ "bos_token_id": 1,
17
+ "classifier_proj_size": 256,
18
+ "codevector_dim": 256,
19
+ "contrastive_logits_temperature": 0.1,
20
+ "conv_bias": false,
21
+ "conv_dim": [
22
+ 512,
23
+ 512,
24
+ 512,
25
+ 512,
26
+ 512,
27
+ 512,
28
+ 512
29
+ ],
30
+ "conv_kernel": [
31
+ 10,
32
+ 3,
33
+ 3,
34
+ 3,
35
+ 3,
36
+ 2,
37
+ 2
38
+ ],
39
+ "conv_stride": [
40
+ 5,
41
+ 2,
42
+ 2,
43
+ 2,
44
+ 2,
45
+ 2,
46
+ 2
47
+ ],
48
+ "ctc_loss_reduction": "sum",
49
+ "ctc_zero_infinity": false,
50
+ "diversity_loss_weight": 0.1,
51
+ "do_stable_layer_norm": false,
52
+ "eos_token_id": 2,
53
+ "feat_extract_activation": "gelu",
54
+ "feat_extract_norm": "group",
55
+ "feat_proj_dropout": 0.1,
56
+ "feat_quantizer_dropout": 0.0,
57
+ "final_dropout": 0.0,
58
+ "freeze_feat_extract_train": true,
59
+ "hidden_act": "gelu",
60
+ "hidden_dropout": 0.1,
61
+ "hidden_size": 768,
62
+ "id2label": {
63
+ "0": "LABEL_0",
64
+ "1": "LABEL_1",
65
+ "2": "LABEL_2",
66
+ "3": "LABEL_3",
67
+ "4": "LABEL_4",
68
+ "5": "LABEL_5",
69
+ "6": "LABEL_6",
70
+ "7": "LABEL_7",
71
+ "8": "LABEL_8",
72
+ "9": "LABEL_9",
73
+ "10": "LABEL_10",
74
+ "11": "LABEL_11",
75
+ "12": "LABEL_12",
76
+ "13": "LABEL_13",
77
+ "14": "LABEL_14",
78
+ "15": "LABEL_15",
79
+ "16": "LABEL_16",
80
+ "17": "LABEL_17",
81
+ "18": "LABEL_18",
82
+ "19": "LABEL_19",
83
+ "20": "LABEL_20",
84
+ "21": "LABEL_21",
85
+ "22": "LABEL_22",
86
+ "23": "LABEL_23"
87
+ },
88
+ "initializer_range": 0.02,
89
+ "intermediate_size": 3072,
90
+ "label2id": {
91
+ "LABEL_0": 0,
92
+ "LABEL_1": 1,
93
+ "LABEL_10": 10,
94
+ "LABEL_11": 11,
95
+ "LABEL_12": 12,
96
+ "LABEL_13": 13,
97
+ "LABEL_14": 14,
98
+ "LABEL_15": 15,
99
+ "LABEL_16": 16,
100
+ "LABEL_17": 17,
101
+ "LABEL_18": 18,
102
+ "LABEL_19": 19,
103
+ "LABEL_2": 2,
104
+ "LABEL_20": 20,
105
+ "LABEL_21": 21,
106
+ "LABEL_22": 22,
107
+ "LABEL_23": 23,
108
+ "LABEL_3": 3,
109
+ "LABEL_4": 4,
110
+ "LABEL_5": 5,
111
+ "LABEL_6": 6,
112
+ "LABEL_7": 7,
113
+ "LABEL_8": 8,
114
+ "LABEL_9": 9
115
+ },
116
+ "layer_norm_eps": 1e-05,
117
+ "layerdrop": 0.0,
118
+ "mask_channel_length": 10,
119
+ "mask_channel_min_space": 1,
120
+ "mask_channel_other": 0.0,
121
+ "mask_channel_prob": 0.0,
122
+ "mask_channel_selection": "static",
123
+ "mask_feature_length": 10,
124
+ "mask_feature_min_masks": 0,
125
+ "mask_feature_prob": 0.0,
126
+ "mask_time_length": 10,
127
+ "mask_time_min_masks": 2,
128
+ "mask_time_min_space": 1,
129
+ "mask_time_other": 0.0,
130
+ "mask_time_prob": 0.05,
131
+ "mask_time_selection": "static",
132
+ "model_type": "wav2vec2multihead_3class",
133
+ "no_mask_channel_overlap": false,
134
+ "no_mask_time_overlap": false,
135
+ "num_adapter_layers": 3,
136
+ "num_attention_heads": 12,
137
+ "num_codevector_groups": 2,
138
+ "num_codevectors_per_group": 320,
139
+ "num_conv_pos_embedding_groups": 16,
140
+ "num_conv_pos_embeddings": 128,
141
+ "num_feat_extract_layers": 7,
142
+ "num_hidden_layers": 12,
143
+ "num_labels_1": 6,
144
+ "num_labels_2": 14,
145
+ "num_labels_3": 4,
146
+ "num_negatives": 100,
147
+ "output_hidden_size": 768,
148
+ "pad_token_id": 0,
149
+ "proj_codevector_dim": 256,
150
+ "tdnn_dilation": [
151
+ 1,
152
+ 2,
153
+ 3,
154
+ 1,
155
+ 1
156
+ ],
157
+ "tdnn_dim": [
158
+ 512,
159
+ 512,
160
+ 512,
161
+ 512,
162
+ 1500
163
+ ],
164
+ "tdnn_kernel": [
165
+ 5,
166
+ 3,
167
+ 3,
168
+ 1,
169
+ 1
170
+ ],
171
+ "torch_dtype": "float32",
172
+ "transformers_version": "4.53.0",
173
+ "use_weighted_layer_sum": false,
174
+ "vocab_size": 32,
175
+ "xvector_output_dim": 512
176
+ }
configuration_wav2vec2multihead.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import Wav2Vec2Config
2
+
3
+
4
+ class Wav2Vec2MultiHeadConfig(Wav2Vec2Config):
5
+ model_type = "wav2vec2multihead_3class"
6
+ is_encoder_decoder = False
7
+
8
+ def __init__(self, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.num_labels_1 = kwargs.pop("num_labels_1", 0)
11
+ self.num_labels_2 = kwargs.pop("num_labels_2", 0)
12
+ self.num_labels_3 = kwargs.pop("num_labels_3", 0)
13
+ self.num_labels = self.num_labels_1 + self.num_labels_2 + self.num_labels_3
14
+
15
+
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aea9c650ef257cc7feb5ba66af251bdda873adf7d91713c24b58f22c4904a777
3
+ size 377586832
modeling_wav2vec2multihead.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from dataclasses import dataclass
2
+ from typing import Optional
3
+
4
+ import torch
5
+ from torch import nn
6
+ from transformers import (
7
+ Wav2Vec2Model,
8
+ Wav2Vec2PreTrainedModel,
9
+ )
10
+ from transformers.utils import ModelOutput
11
+
12
+
13
+ @dataclass
14
+ class Wav2Vec2MultiHeadMultiLabelOutput(ModelOutput):
15
+ loss: Optional[torch.FloatTensor] = None
16
+ logits1: torch.FloatTensor = None
17
+ logits2: torch.FloatTensor = None
18
+ logits3: torch.FloatTensor = None
19
+ hidden_states: Optional[tuple[torch.FloatTensor]] = None
20
+ attentions: Optional[tuple[torch.FloatTensor]] = None
21
+
22
+
23
+ class Wav2Vec2ForMultiHeadMultiLabelClassification(Wav2Vec2PreTrainedModel):
24
+ def __init__(self, config):
25
+ super().__init__(config)
26
+ self.wav2vec2 = Wav2Vec2Model(config)
27
+ self.dropout = nn.Dropout(config.final_dropout)
28
+ self.classifier1 = nn.Linear(config.hidden_size, config.num_labels_1)
29
+ self.classifier2 = nn.Linear(config.hidden_size, config.num_labels_2)
30
+ self.classifier3 = nn.Linear(config.hidden_size, config.num_labels_3)
31
+ self.init_weights()
32
+
33
+ def freeze_feature_extractor(self):
34
+ self.wav2vec2.feature_extractor._freeze_parameters()
35
+
36
+ def freeze_cnn_projection(self):
37
+ for param in self.wav2vec2.feature_projection.parameters():
38
+ param.requires_grad = False
39
+
40
+ def forward(
41
+ self,
42
+ input_values,
43
+ attention_mask=None,
44
+ labels1=None,
45
+ labels2=None,
46
+ labels3=None,
47
+ output_attentions=None,
48
+ output_hidden_states=None,
49
+ return_dict=None,
50
+ ):
51
+ return_dict = (
52
+ return_dict if return_dict is not None else self.config.use_return_dict
53
+ )
54
+ outputs = self.wav2vec2(
55
+ input_values,
56
+ attention_mask=attention_mask,
57
+ output_attentions=output_attentions,
58
+ output_hidden_states=output_hidden_states,
59
+ return_dict=return_dict,
60
+ )
61
+
62
+ hidden_states = outputs[0]
63
+ hidden_states = self.dropout(hidden_states)
64
+ hidden_states = torch.mean(hidden_states, dim=1)
65
+
66
+ logits1 = self.classifier1(hidden_states)
67
+ logits2 = self.classifier2(hidden_states)
68
+ logits3 = self.classifier3(hidden_states)
69
+
70
+ loss = None
71
+ if labels1 is not None and labels2 is not None and labels3 is not None:
72
+ loss_fct = nn.CrossEntropyLoss()
73
+ loss1 = loss_fct(
74
+ logits1.view(-1, self.config.num_labels_1), labels1.view(-1)
75
+ )
76
+ loss2 = loss_fct(
77
+ logits2.view(-1, self.config.num_labels_2), labels2.view(-1)
78
+ )
79
+ loss3 = loss_fct(
80
+ logits3.view(-1, self.config.num_labels_3), labels3.view(-1)
81
+ )
82
+ loss = loss1 + loss2 + loss3
83
+
84
+ return Wav2Vec2MultiHeadMultiLabelOutput(
85
+ loss=loss,
86
+ logits1=logits1,
87
+ logits2=logits2,
88
+ logits3=logits3,
89
+ hidden_states=outputs.hidden_states,
90
+ attentions=outputs.attentions,
91
+ )