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

Method encode

funasr/models/transformer/model.py:288–325  ·  view source on GitHub ↗

Frontend + 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

286 return loss, stats, weight
287
288 def encode(
289 self,
290 speech: torch.Tensor,
291 speech_lengths: torch.Tensor,
292 **kwargs,
293 ) -> Tuple[torch.Tensor, torch.Tensor]:
294 """Frontend + Encoder. Note that this method is used by asr_inference.py
295 Args:
296 speech: (Batch, Length, ...)
297 speech_lengths: (Batch, )
298 ind: int
299 """
300 with autocast(False):
301
302 # Data augmentation
303 if self.specaug is not None and self.training:
304 speech, speech_lengths = self.specaug(speech, speech_lengths)
305
306 # Normalization for feature: e.g. Global-CMVN, Utterance-CMVN
307 if self.normalize is not None:
308 speech, speech_lengths = self.normalize(speech, speech_lengths)
309
310 # Forward encoder
311 # feats: (Batch, Length, Dim)
312 # -> encoder_out: (Batch, Length2, Dim2)
313 if self.encoder.interctc_use_conditioning:
314 encoder_out, encoder_out_lens, _ = self.encoder(speech, speech_lengths, ctc=self.ctc)
315 else:
316 encoder_out, encoder_out_lens, _ = self.encoder(speech, speech_lengths)
317 intermediate_outs = None
318 if isinstance(encoder_out, tuple):
319 intermediate_outs = encoder_out[1]
320 encoder_out = encoder_out[0]
321
322 if intermediate_outs is not None:
323 return (encoder_out, intermediate_outs), encoder_out_lens
324
325 return encoder_out, encoder_out_lens
326
327 def _calc_att_loss(
328 self,

Callers 3

forwardMethod · 0.95
inference_batch_ctcMethod · 0.95
inferenceMethod · 0.95

Calls 2

autocastFunction · 0.90
normalizeMethod · 0.45

Tested by

no test coverage detected