wav2vec for pre-training to extract high-dimensional speech features from datasets

Gorgen: <p>Dear everyone: Is there any tutorial on using wav2vec for pre-training to extract high-dimensional speech features from datasets? thanks, best wishes</p>

nateanl: <p>Hi <a class="mention" href="/u/gorgen">@Gorgen</a>, you can check the <a href="https://pytorch.org/audio/stable/pipelines.html#torchaudio.pipelines.Wav2Vec2Bundle" rel="noopener nofollow ugc">Wav2Vec2Bundle</a> for extracting features by Wav2Vec2 or HuBERT pre-trained models.</p>

Gorgen: <p>Dear nateanl:</p>
<p>Thank you for your help.<br>
best wishes</p>

Gorgen: <p>Hello nateanl: I am sorry to disturb you again. When I follow the HuBert tutorials to extract audio features.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/d/a/da0f919b48732d163782e0c872ccb8291db3a2b6.png" data-download-href="https://discuss.pytorch.org/uploads/default/da0f919b48732d163782e0c872ccb8291db3a2b6" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/d/a/da0f919b48732d163782e0c872ccb8291db3a2b6_2_671x500.png" alt="image" data-base62-sha1="v73ryGdjSA6RPzYMwFagvnvsK8u" width="671" height="500" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/d/a/da0f919b48732d163782e0c872ccb8291db3a2b6_2_671x500.png, https://discuss.pytorch.org/uploads/default/original/3X/d/a/da0f919b48732d163782e0c872ccb8291db3a2b6.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/d/a/da0f919b48732d163782e0c872ccb8291db3a2b6.png 2x" data-dominant-color="F4F3F3"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">977×727 54.1 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/0/e0a366c358b950900a5d6fdf7300929f204add21.png" data-download-href="https://discuss.pytorch.org/uploads/default/e0a366c358b950900a5d6fdf7300929f204add21" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/e/0/e0a366c358b950900a5d6fdf7300929f204add21.png" alt="image" data-base62-sha1="w3f2r5obAi7yfMzkMw9ttUG7D5D" width="591" height="500" data-dominant-color="F2F4F2"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">616×521 9.39 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div><br>
Finally, features, _ = model.extract_features(waveform) features are saved in the form of a list. There are a total of 12 elements in the list, each element is in the form of tensor, and the shape is [2, 40, 768]. So when you finally use the feature, do you stack the 12 tensor directly and shape it into [12, 2, 40, 768]. Is there a theoretical problem with doing this?</p>
<p>Could you please give me some suggestions?<br>
Thanks</p>

nateanl: <p>The 12 elements are the outputs of each transformer layer. For example, the first element is the output of the first transformer.</p>
<p>You can use one of the elements as the feature. The other way is weighting sum or take the average of the 12 Tensors as the feature. In either way, the shape of the final feature will be [2, 40, 768], where 2 is the batch size, 40 is the number of frames, and 768 is the feature dimension.</p>

Gorgen: <p>I am grateful for your detailed guidance. Thanks, best wishes</p>

Gorgen: <p>sorry. I disturb you again. To be honest, I know each transformer layer are suitable for different downstream tasks.  Emotion recognition, ASR, PR, and etc are needed to utilze different transformer layer(the original paper is SUPERB: Speech processing Universal PERformance Benchmark). However, they said “PR, KS, SID,IC, ER are simple tasks that are solvable with<br>
linear downstream models. Hence, we use a frame-wise linear<br>
transformation for PR with CTC loss; mean-pooling followed<br>
by a linear transformation with cross-entropy loss for utterancelevel tasks (KS, SID, IC, and ER)”.  I don’t know where is the frae-wise linear transformation compared to 12 transformers. Could you please give me some suggestions?  Thanks</p>

nateanl: <p>frame-wise linear transformation is just the normal torch.nn.Linear layer.<br>
For ASR task, the process is like<br>
waveform → transformer feature → nn.Linear → CTC loss<br>
For KS, SID, IC, and ER task, the process is<br>
waveform → transformer feature → mean pooling → nn.Linear → other losses</p>

Gorgen: <p>Thank you for your detailed explanation. sorry. I’m new to deep learning. I have problem. I want to know which transformers represent the process that is suitable for KS, SID, IC and ER task (waveform → transformer feature → mean pooling → nn.Linear → other losses)? I especially want to know exactly which layer can be used forER task?</p>
<p>Thanks<br>
best wishes</p>

nateanl: <p>It depends on your dataset. I suggest trying with different layers’ outputs and compare the performances on the development set, and choose the one with highest accuracy. Another other method is weighting sum all layers’ outputs as the input feature.</p>

Gorgen: <p>My task is about emotion recognition. I have noticed the superB benchmarr. it suggested PR, KS, SID,IC, ER are simple tasks that are solvable with<br>
linear downstream models. Hence, we use a frame-wise linear<br>
transformation for PR with CTC loss; mean-pooling followed<br>
by a linear transformation with cross-entropy loss for utterancelevel tasks (KS, SID, IC, and ER). so, which layer? layer 1 or layer 2, or other? Thanks, best wishes</p>

nateanl: <p>Thanks for providing the details. Even for emotion recognition task, if the dataset is different, the performance of the transformer features may be different. For example, the 6th layer is optimal for emotion recognition dataset A, but it may not be optimal for emotion recognition dataset B.</p>
<p>I suggest using layer 1, layer 6 and layer 12 to conduct three experiments, and compare the performances. So that you have a better idea of which layer is optimal for your task.</p>
<p>Best,</p>

Gorgen: <p>I am grateful for your detailed suggestions. Thank you for your advice.<br>
best wishes</p>

delo_ch: <p>Please <a class="mention" href="/u/nateanl">@nateanl</a>, After weighting sum over the 12 Tensors. I would like to know the mean pooling used it is applied for frames or for features?</p>

nateanl: <p>Hi <a class="mention" href="/u/delo_ch">@delo_ch</a>, I’m not sure what the 12 Tensors are, but mean pooling is applied on the frame dimension, if the previous feature Tensor is of shape <code>(batch, frame, feature_dim)</code>, after mean pooling the shape will be <code>(batch, feature_dim)</code>. Thanks.</p>

delo_ch: <p>Thanks, <a class="mention" href="/u/nateanl">@nateanl</a> for your feedback. In fact, the 12 tensors are the features obtained from the 12 layers, which have the following shape <code>(12, number_of_frames, feature_dimension)</code> and each layer has the shape (number of frames, feature dimension), what is commonly used is to apply the average over the weights of all the layers to have a vector with the shape <code>(1, number_of_frames, feature_dimension)</code>. When we apply the average, we set up the process of mean pooling, but I would like to know if we can use it on the feature dimension instead of the frame dimension.</p>

nateanl: <p>applying it on feature dimension doesn’t make much sense, especially when your input has different lengths, then each feature Tensor ends up with different dimensions.</p>

delo_ch: <p>Yes, that is the major problem. OK, thank you <a class="mention" href="/u/nateanl">@nateanl</a></p>