Construct Efficient Conformer Encoder Args: input_size to use_dynamic_chunk, see in BaseEncoder macaron_style (bool): Whether to use macaron style for positionwise layer. activation_type (str): Encoder activation function type.
(self,
input_size: int,
output_size: int = 256,
attention_heads: int = 4,
linear_units: int = 2048,
num_blocks: int = 6,
dropout_rate: float = 0.1,
positional_dropout_rate: float = 0.1,
attention_dropout_rate: float = 0.0,
input_layer: str = "conv2d",
pos_enc_layer_type: str = "rel_pos",
normalize_before: bool = True,
static_chunk_size: int = 0,
use_dynamic_chunk: bool = False,
global_cmvn: torch.nn.Module = None,
use_dynamic_left_chunk: bool = False,
macaron_style: bool = True,
activation_type: str = "swish",
use_cnn_module: bool = True,
cnn_module_kernel: int = 15,
causal: bool = False,
cnn_module_norm: str = "batch_norm",
stride_layer_idx: Optional[Union[int, List[int]]] = 3,
stride: Optional[Union[int, List[int]]] = 2,
group_layer_idx: Optional[Union[int, List[int],
tuple]] = (0, 1, 2, 3),
group_size: int = 3,
stride_kernel: bool = True,
**kwargs)
| 42 | """Conformer encoder module.""" |
| 43 | |
| 44 | def __init__(self, |
| 45 | input_size: int, |
| 46 | output_size: int = 256, |
| 47 | attention_heads: int = 4, |
| 48 | linear_units: int = 2048, |
| 49 | num_blocks: int = 6, |
| 50 | dropout_rate: float = 0.1, |
| 51 | positional_dropout_rate: float = 0.1, |
| 52 | attention_dropout_rate: float = 0.0, |
| 53 | input_layer: str = "conv2d", |
| 54 | pos_enc_layer_type: str = "rel_pos", |
| 55 | normalize_before: bool = True, |
| 56 | static_chunk_size: int = 0, |
| 57 | use_dynamic_chunk: bool = False, |
| 58 | global_cmvn: torch.nn.Module = None, |
| 59 | use_dynamic_left_chunk: bool = False, |
| 60 | macaron_style: bool = True, |
| 61 | activation_type: str = "swish", |
| 62 | use_cnn_module: bool = True, |
| 63 | cnn_module_kernel: int = 15, |
| 64 | causal: bool = False, |
| 65 | cnn_module_norm: str = "batch_norm", |
| 66 | stride_layer_idx: Optional[Union[int, List[int]]] = 3, |
| 67 | stride: Optional[Union[int, List[int]]] = 2, |
| 68 | group_layer_idx: Optional[Union[int, List[int], |
| 69 | tuple]] = (0, 1, 2, 3), |
| 70 | group_size: int = 3, |
| 71 | stride_kernel: bool = True, |
| 72 | **kwargs): |
| 73 | """Construct Efficient Conformer Encoder |
| 74 | |
| 75 | Args: |
| 76 | input_size to use_dynamic_chunk, see in BaseEncoder |
| 77 | macaron_style (bool): Whether to use macaron style for |
| 78 | positionwise layer. |
| 79 | activation_type (str): Encoder activation function type. |
| 80 | use_cnn_module (bool): Whether to use convolution module. |
| 81 | cnn_module_kernel (int): Kernel size of convolution module. |
| 82 | causal (bool): whether to use causal convolution or not. |
| 83 | stride_layer_idx (list): layer id with StrideConv, start from 0 |
| 84 | stride (list): stride size of each StrideConv in efficient conformer |
| 85 | group_layer_idx (list): layer id with GroupedAttention, start from 0 |
| 86 | group_size (int): group size of every GroupedAttention layer |
| 87 | stride_kernel (bool): default True. True: recompute cnn kernels with stride. |
| 88 | """ |
| 89 | super().__init__() |
| 90 | self._output_size = output_size |
| 91 | |
| 92 | logging.info( |
| 93 | f"input_layer = {input_layer}, " |
| 94 | f"subsampling_class = {WENET_SUBSAMPLE_CLASSES[input_layer]}") |
| 95 | |
| 96 | self.global_cmvn = global_cmvn |
| 97 | self.embed = WENET_SUBSAMPLE_CLASSES[input_layer]( |
| 98 | input_size, |
| 99 | output_size, |
| 100 | dropout_rate, |
| 101 | WENET_EMB_CLASSES[pos_enc_layer_type](output_size, |
nothing calls this directly
no test coverage detected