Audio Classification
Transformers
Safetensors
Slovenian
Croatian
Serbian
wav2vec2-bert
audio-frame-classification
5roop commited on
Commit
c9ad0c5
·
verified ·
1 Parent(s): cbd3ea2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +96 -121
README.md CHANGED
@@ -15,11 +15,9 @@ base_model:
15
  - facebook/w2v-bert-2.0
16
  ---
17
 
18
- # Model Card for Model ID
19
-
20
- <!-- Provide a quick summary of what the model is/does. -->
21
-
22
 
 
23
 
24
  ## Model Details
25
 
@@ -38,37 +36,98 @@ This is the model card of a 🤗 transformers model that has been pushed on the
38
 
39
  <!-- Provide the basic links for the model. -->
40
 
41
- - **Repository:** [More Information Needed]
42
- - **Paper [optional]:** [More Information Needed]
43
- - **Demo [optional]:** [More Information Needed]
44
-
45
- ## Uses
46
 
47
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
48
 
49
  ### Direct Use
50
 
51
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
52
-
53
- [More Information Needed]
54
-
55
- ### Downstream Use [optional]
56
-
57
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
58
-
59
- [More Information Needed]
60
-
61
- ### Out-of-Scope Use
62
-
63
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
64
-
65
- [More Information Needed]
66
-
67
- ## Bias, Risks, and Limitations
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
 
69
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
70
-
71
- [More Information Needed]
72
 
73
  ### Recommendations
74
 
@@ -101,13 +160,11 @@ Use the code below to get started with the model.
101
 
102
  #### Training Hyperparameters
103
 
104
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
105
-
106
- #### Speeds, Sizes, Times [optional]
107
-
108
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
109
-
110
- [More Information Needed]
111
 
112
  ## Evaluation
113
 
@@ -115,94 +172,12 @@ Use the code below to get started with the model.
115
 
116
  ### Testing Data, Factors & Metrics
117
 
118
- #### Testing Data
119
-
120
- <!-- This should link to a Dataset Card if possible. -->
121
-
122
- [More Information Needed]
123
-
124
- #### Factors
125
-
126
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
127
-
128
- [More Information Needed]
129
-
130
- #### Metrics
131
-
132
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
133
-
134
- [More Information Needed]
135
-
136
- ### Results
137
-
138
- [More Information Needed]
139
 
140
  #### Summary
141
 
142
 
143
 
144
- ## Model Examination [optional]
145
-
146
- <!-- Relevant interpretability work for the model goes here -->
147
-
148
- [More Information Needed]
149
-
150
- ## Environmental Impact
151
-
152
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
153
-
154
- 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).
155
-
156
- - **Hardware Type:** [More Information Needed]
157
- - **Hours used:** [More Information Needed]
158
- - **Cloud Provider:** [More Information Needed]
159
- - **Compute Region:** [More Information Needed]
160
- - **Carbon Emitted:** [More Information Needed]
161
-
162
- ## Technical Specifications [optional]
163
-
164
- ### Model Architecture and Objective
165
-
166
- [More Information Needed]
167
-
168
- ### Compute Infrastructure
169
-
170
- [More Information Needed]
171
-
172
- #### Hardware
173
-
174
- [More Information Needed]
175
-
176
- #### Software
177
-
178
- [More Information Needed]
179
-
180
- ## Citation [optional]
181
-
182
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
183
-
184
- **BibTeX:**
185
-
186
- [More Information Needed]
187
-
188
- **APA:**
189
-
190
- [More Information Needed]
191
-
192
- ## Glossary [optional]
193
-
194
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
195
-
196
- [More Information Needed]
197
-
198
- ## More Information [optional]
199
-
200
- [More Information Needed]
201
-
202
- ## Model Card Authors [optional]
203
-
204
- [More Information Needed]
205
 
206
- ## Model Card Contact
207
 
208
- [More Information Needed]
 
15
  - facebook/w2v-bert-2.0
16
  ---
17
 
18
+ # Model Card
 
 
 
19
 
20
+ This model annotates primary stress in words on 20ms frames.
21
 
22
  ## Model Details
23
 
 
36
 
37
  <!-- Provide the basic links for the model. -->
38
 
39
+ - **Paper [optional]:** Coming soon
 
 
 
 
40
 
 
41
 
42
  ### Direct Use
43
 
44
+ The model is intended for data-driven analyses in primary stress position. ATM, it has been proven to work on 4 datasets in 3 languages.
45
+
46
+
47
+ ## Example use
48
+
49
+ ```python
50
+ import numpy as np
51
+
52
+ from datasets import Audio, Dataset
53
+ from transformers import AutoFeatureExtractor, Wav2Vec2BertForAudioFrameClassification
54
+ import torch
55
+ import numpy as np
56
+
57
+ if torch.cuda.is_available():
58
+ device = torch.device("cuda")
59
+ else:
60
+ device = torch.device("cpu")
61
+
62
+ model_name = "5roop/Wav2Vec2BertPrimaryStressAudioFrameClassifier"
63
+ feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
64
+ model = Wav2Vec2BertForAudioFrameClassification.from_pretrained(model_name).to(device)
65
+ # Path to the file, containing the word to be annotated:
66
+ f = "wavs/word.wav"
67
+
68
+
69
+ def frames_to_intervals(frames: list[int]) -> list[tuple[float]]:
70
+ from itertools import pairwise
71
+ import pandas as pd
72
+
73
+ results = []
74
+ ndf = pd.DataFrame(
75
+ data={
76
+ "time_s": [0.020 * i for i in range(len(frames))],
77
+ "frames": frames,
78
+ }
79
+ )
80
+ ndf = ndf.dropna()
81
+ indices_of_change = ndf.frames.diff()[ndf.frames.diff() != 0].index.values
82
+ for si, ei in pairwise(indices_of_change):
83
+ if ndf.loc[si : ei - 1, "frames"].mode()[0] == 0:
84
+ pass
85
+ else:
86
+ results.append(
87
+ (round(ndf.loc[si, "time_s"], 3), round(ndf.loc[ei - 1, "time_s"], 3))
88
+ )
89
+ if results == []:
90
+ return None
91
+ # Post-processing: if multiple regions were returned, only the longest should be taken:
92
+ if len(results) > 1:
93
+ results = sorted(results, key=lambda t: t[1]-t[0], reverse=True)
94
+ return results[0:1]
95
+
96
+
97
+ def evaluator(chunks):
98
+ sampling_rate = chunks["audio"][0]["sampling_rate"]
99
+ with torch.no_grad():
100
+ inputs = feature_extractor(
101
+ [i["array"] for i in chunks["audio"]],
102
+ return_tensors="pt",
103
+ sampling_rate=sampling_rate,
104
+ ).to(device)
105
+ logits = model(**inputs).logits
106
+ y_pred_raw = np.array(logits.cpu())
107
+ y_pred = y_pred_raw.argmax(axis=-1)
108
+ primary_stress = [frames_to_intervals(i) for i in y_pred]
109
+ return {
110
+ "y_pred": y_pred,
111
+ "y_pred_logits": y_pred_raw,
112
+ "primary_stress": primary_stress,
113
+ }
114
+
115
+ # Create a dataset with a single instance and map our evaluator function on it:
116
+ ds = Dataset.from_dict({"audio": [f]}).cast_column("audio", Audio(16000, mono=True))
117
+ ds = ds.map(evaluator, batched=True, batch_size=1) # Adjust batch size according to your hardware specs
118
+ print(ds["y_pred"][0])
119
+ # Outputs: [0, 0, 1, 1, 1, 1, 1, ...]
120
+ print(ds["y_pred_logits"][0])
121
+ # Outputs:
122
+ # [[ 0.89419061, -0.77746612],
123
+ # [ 0.44213724, -0.34862748],
124
+ # [-0.08605709, 0.13012762],
125
+ # ....
126
+ print(ds["prosodic_units"][0])
127
+ # Outputs: [0.34, 0.4]
128
+
129
+ ```
130
 
 
 
 
131
 
132
  ### Recommendations
133
 
 
160
 
161
  #### Training Hyperparameters
162
 
163
+ - Learning rate: 1e-5
164
+ - Batch size: 32
165
+ - Number of epochs: 20
166
+ - Weight decay: 0.01
167
+ - Gradient accumulation steps: 1
 
 
168
 
169
  ## Evaluation
170
 
 
172
 
173
  ### Testing Data, Factors & Metrics
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
 
176
  #### Summary
177
 
178
 
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
181
+ ## Citation
182
 
183
+ Coming soon