MCPcopy Create free account
hub / github.com/modelscope/FunASR / encode

Method encode

funasr/models/paraformer/model.py:286–313  ·  view source on GitHub ↗

Encoder. Note that this method is used by asr_inference.py Args: speech: (Batch, Length, ...) speech_lengths: (Batch, ) ind: int

(
        self,
        speech: torch.Tensor,
        speech_lengths: torch.Tensor,
        **kwargs,
    )

Source from the content-addressed store, hash-verified

284 return loss, stats, weight
285
286 def encode(
287 self,
288 speech: torch.Tensor,
289 speech_lengths: torch.Tensor,
290 **kwargs,
291 ) -> Tuple[torch.Tensor, torch.Tensor]:
292 """Encoder. Note that this method is used by asr_inference.py
293 Args:
294 speech: (Batch, Length, ...)
295 speech_lengths: (Batch, )
296 ind: int
297 """
298 with autocast(False):
299
300 # Data augmentation
301 if self.specaug is not None and self.training:
302 speech, speech_lengths = self.specaug(speech, speech_lengths)
303
304 # Normalization for feature: e.g. Global-CMVN, Utterance-CMVN
305 if self.normalize is not None:
306 speech, speech_lengths = self.normalize(speech, speech_lengths)
307
308 # Forward encoder
309 encoder_out, encoder_out_lens, _ = self.encoder(speech, speech_lengths)
310 if isinstance(encoder_out, tuple):
311 encoder_out = encoder_out[0]
312
313 return encoder_out, encoder_out_lens
314
315 def calc_predictor(self, encoder_out, encoder_out_lens):
316

Callers 2

forwardMethod · 0.95
inferenceMethod · 0.95

Calls 2

autocastFunction · 0.90
normalizeMethod · 0.45

Tested by

no test coverage detected