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

Method encode2

funasr/models/uniasr/model.py:411–447  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

409 return speech_raw, encoder_out, encoder_out_lens
410
411 def encode2(
412 self,
413 encoder_out: torch.Tensor,
414 encoder_out_lens: torch.Tensor,
415 speech: torch.Tensor,
416 speech_lengths: torch.Tensor,
417 **kwargs,
418 ):
419 """Frontend + Encoder. Note that this method is used by asr_inference.py
420 Args:
421 speech: (Batch, Length, ...)
422 speech_lengths: (Batch, )
423 """
424
425 ind = kwargs.get("ind", 0)
426 encoder_out_rm, encoder_out_lens_rm = self.encoder.overlap_chunk_cls.remove_chunk(
427 encoder_out,
428 encoder_out_lens,
429 chunk_outs=None,
430 )
431 # residual_input
432 encoder_out = torch.cat((speech, encoder_out_rm), dim=-1)
433 encoder_out_lens = encoder_out_lens_rm
434 if self.stride_conv is not None:
435 speech, speech_lengths = self.stride_conv(encoder_out, encoder_out_lens)
436 if not self.encoder1_encoder2_joint_training:
437 speech = speech.detach()
438 speech_lengths = speech_lengths.detach()
439 # 4. Forward encoder
440 # feats: (Batch, Length, Dim)
441 # -> encoder_out: (Batch, Length2, Dim2)
442
443 encoder_out, encoder_out_lens, _ = self.encoder2(speech, speech_lengths, ind=ind)
444 if isinstance(encoder_out, tuple):
445 encoder_out = encoder_out[0]
446
447 return encoder_out, encoder_out_lens
448
449 def nll(
450 self,

Callers 2

forwardMethod · 0.95
inferenceMethod · 0.95

Calls 1

remove_chunkMethod · 0.80

Tested by

no test coverage detected