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

Function make_source_mask

funasr/models/transformer/utils/nets_utils.py:648–665  ·  view source on GitHub ↗

Create source mask for given lengths. Reference: https://github.com/k2-fsa/icefall/blob/master/icefall/utils.py Args: lengths: Sequence lengths. (B,) Returns: : Mask for the sequence lengths. (B, max_len)

(lengths: torch.Tensor)

Source from the content-addressed store, hash-verified

646
647
648def make_source_mask(lengths: torch.Tensor) -> torch.Tensor:
649 """Create source mask for given lengths.
650
651 Reference: https://github.com/k2-fsa/icefall/blob/master/icefall/utils.py
652
653 Args:
654 lengths: Sequence lengths. (B,)
655
656 Returns:
657 : Mask for the sequence lengths. (B, max_len)
658
659 """
660 max_len = lengths.max()
661 batch_size = lengths.size(0)
662
663 expanded_lengths = torch.arange(max_len).expand(batch_size, max_len).to(lengths)
664
665 return expanded_lengths >= lengths.unsqueeze(1)
666
667
668def get_transducer_task_io(

Callers 5

forwardMethod · 0.90
full_utt_forwardMethod · 0.90
simu_chunk_forwardMethod · 0.90
chunk_forwardMethod · 0.90
forwardMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…