Encodes the input features into the output space. Args: extract_features (torch.Tensor): The extracted features from the audio signal. attention_mask (torch.Tensor, optional): Attention mask to be used for padding. mask_time_indices (torch.Tensor
(
self,
extract_features,
attention_mask=None,
mask_time_indices=None,
output_attentions=None,
output_hidden_states=None,
return_dict=None,
)
| 116 | return extract_features |
| 117 | |
| 118 | def encode( |
| 119 | self, |
| 120 | extract_features, |
| 121 | attention_mask=None, |
| 122 | mask_time_indices=None, |
| 123 | output_attentions=None, |
| 124 | output_hidden_states=None, |
| 125 | return_dict=None, |
| 126 | ): |
| 127 | """ |
| 128 | Encodes the input features into the output space. |
| 129 | |
| 130 | Args: |
| 131 | extract_features (torch.Tensor): The extracted features from the audio signal. |
| 132 | attention_mask (torch.Tensor, optional): Attention mask to be used for padding. |
| 133 | mask_time_indices (torch.Tensor, optional): Masked indices for the time dimension. |
| 134 | output_attentions (bool, optional): If set to True, returns the attention weights. |
| 135 | output_hidden_states (bool, optional): If set to True, returns all hidden states. |
| 136 | return_dict (bool, optional): If set to True, returns a BaseModelOutput instead of the tuple. |
| 137 | |
| 138 | Returns: |
| 139 | The encoded output features. |
| 140 | """ |
| 141 | self.config.output_attentions = True |
| 142 | |
| 143 | output_hidden_states = ( |
| 144 | output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states |
| 145 | ) |
| 146 | return_dict = return_dict if return_dict is not None else self.config.use_return_dict |
| 147 | |
| 148 | if attention_mask is not None: |
| 149 | # compute reduced attention_mask corresponding to feature vectors |
| 150 | attention_mask = self._get_feature_vector_attention_mask( |
| 151 | extract_features.shape[1], attention_mask, add_adapter=False |
| 152 | ) |
| 153 | |
| 154 | hidden_states, extract_features = self.feature_projection(extract_features) |
| 155 | hidden_states = self._mask_hidden_states( |
| 156 | hidden_states, mask_time_indices=mask_time_indices, attention_mask=attention_mask |
| 157 | ) |
| 158 | |
| 159 | encoder_outputs = self.encoder( |
| 160 | hidden_states, |
| 161 | attention_mask=attention_mask, |
| 162 | output_attentions=output_attentions, |
| 163 | output_hidden_states=output_hidden_states, |
| 164 | return_dict=return_dict, |
| 165 | ) |
| 166 | |
| 167 | hidden_states = encoder_outputs[0] |
| 168 | |
| 169 | if self.adapter is not None: |
| 170 | hidden_states = self.adapter(hidden_states) |
| 171 | |
| 172 | if not return_dict: |
| 173 | return (hidden_states, ) + encoder_outputs[1:] |
| 174 | return BaseModelOutput( |
| 175 | last_hidden_state=hidden_states, |
nothing calls this directly
no outgoing calls
no test coverage detected