@@ -14,10 +14,10 @@ class _PositionwiseFeedForward(nn.Module):
14
14
FF -> Activation -> Dropout -> FF
15
15
"""
16
16
17
- def __init__ (self , d_model : int , d_ff : int , dropout : float , activation , l2 : float = 0.0 ):
17
+ def __init__ (self , dim_model : int , dim_ff : int , dropout : float , activation , l2 : float = 0.0 ):
18
18
"""
19
- :param d_model :
20
- :param d_ff :
19
+ :param dim_model :
20
+ :param dim_ff :
21
21
:param dropout:
22
22
:param activation:
23
23
:param l2:
@@ -27,8 +27,8 @@ def __init__(self, d_model: int, d_ff: int, dropout: float, activation, l2: floa
27
27
self .dropout = dropout
28
28
self .activation = activation
29
29
30
- self .linear1 = nn .Linear (n_out = d_ff , l2 = l2 )
31
- self .linear2 = nn .Linear (n_out = d_model , l2 = l2 )
30
+ self .linear1 = nn .Linear (n_out = dim_ff , l2 = l2 )
31
+ self .linear2 = nn .Linear (n_out = dim_model , l2 = l2 )
32
32
33
33
def forward (self , inp : LayerRef ) -> LayerRef :
34
34
return self .linear2 (nn .dropout (self .activation (self .linear1 (inp )), dropout = self .dropout ))
@@ -40,17 +40,17 @@ class _ConformerConvBlock(nn.Module):
40
40
FF -> GLU -> depthwise conv -> BN -> Swish -> FF
41
41
"""
42
42
43
- def __init__ (self , d_model : int , kernel_size : Tuple [int ], l2 : float = 0.0 ):
43
+ def __init__ (self , dim_model : int , kernel_size : Tuple [int ], l2 : float = 0.0 ):
44
44
"""
45
- :param d_model :
45
+ :param dim_model :
46
46
:param kernel_size:
47
47
:param l2:
48
48
"""
49
49
super ().__init__ ()
50
50
51
- self .positionwise_conv1 = nn .Linear (n_out = d_model * 2 , l2 = l2 )
52
- self .depthwise_conv = nn .Conv (n_out = d_model , filter_size = kernel_size , groups = d_model , l2 = l2 , padding = 'same' )
53
- self .positionwise_conv2 = nn .Linear (n_out = d_model , l2 = l2 )
51
+ self .positionwise_conv1 = nn .Linear (n_out = dim_model * 2 , l2 = l2 )
52
+ self .depthwise_conv = nn .Conv (n_out = dim_model , filter_size = kernel_size , groups = dim_model , l2 = l2 , padding = 'same' )
53
+ self .positionwise_conv2 = nn .Linear (n_out = dim_model , l2 = l2 )
54
54
55
55
def forward (self , inp : LayerRef ) -> LayerRef :
56
56
x_conv1 = self .positionwise_conv1 (inp )
@@ -68,15 +68,15 @@ class _ConformerConvSubsampleLayer(nn.Module):
68
68
"""
69
69
70
70
def __init__ (self , filter_sizes : List [Tuple [int , ...]], pool_sizes : Union [List [Tuple [int , ...]], None ],
71
- channel_sizes : List [int ], l2 : float = 0.0 , dropout : float = 0.3 , act : str = 'relu' ,
71
+ channel_sizes : List [int ], l2 : float = 0.0 , dropout : float = 0.3 , activation : str = 'relu' ,
72
72
padding : str = 'same' ):
73
73
"""
74
74
:param filter_sizes:
75
75
:param pool_sizes:
76
76
:param channel_sizes:
77
77
:param l2:
78
78
:param dropout:
79
- :param act :
79
+ :param activation :
80
80
:param padding:
81
81
"""
82
82
super ().__init__ ()
@@ -87,7 +87,7 @@ def __init__(self, filter_sizes: List[Tuple[int, ...]], pool_sizes: Union[List[T
87
87
self .conv_layers = nn .ModuleList ()
88
88
for filter_size , channel_size in zip (filter_sizes , channel_sizes ):
89
89
self .conv_layers .append (
90
- nn .Conv (l2 = l2 , activation = act , filter_size = filter_size , n_out = channel_size , padding = padding ))
90
+ nn .Conv (l2 = l2 , activation = activation , filter_size = filter_size , n_out = channel_size , padding = padding ))
91
91
92
92
def forward (self , inp : LayerRef ) -> LayerRef :
93
93
x = nn .split_dims (inp , axis = 'F' , dims = (- 1 , 1 ))
@@ -106,31 +106,31 @@ class ConformerEncoderLayer(nn.Module):
106
106
Represents a conformer block
107
107
"""
108
108
109
- def __init__ (self , conv_kernel_size : Tuple [int ], ff_act , ff_dim : int , dropout : float , att_dropout : float ,
110
- enc_key_dim : int , att_n_heads : int , l2 : float ):
109
+ def __init__ (self , conv_kernel_size : Tuple [int ], activation_ff , dim_ff : int , dropout : float , att_dropout : float ,
110
+ enc_key_dim : int , num_heads : int , l2 : float ):
111
111
"""
112
112
:param conv_kernel_size:
113
- :param ff_act :
113
+ :param activation_ff :
114
114
:param ff_dim:
115
115
:param dropout:
116
116
:param att_dropout:
117
117
:param enc_key_dim:
118
- :param att_n_heads :
118
+ :param num_heads :
119
119
:param l2:
120
120
"""
121
121
super ().__init__ ()
122
122
123
123
self .dropout = dropout
124
124
125
125
self .ffn1 = _PositionwiseFeedForward (
126
- d_model = enc_key_dim , d_ff = ff_dim , dropout = dropout , activation = ff_act , l2 = l2 )
126
+ dim_model = enc_key_dim , dim_ff = dim_ff , dropout = dropout , activation = activation_ff , l2 = l2 )
127
127
128
128
self .ffn2 = _PositionwiseFeedForward (
129
- d_model = enc_key_dim , d_ff = ff_dim , dropout = dropout , activation = ff_act , l2 = l2 )
129
+ dim_model = enc_key_dim , dim_ff = dim_ff , dropout = dropout , activation = activation_ff , l2 = l2 )
130
130
131
- self .conv_module = _ConformerConvBlock (d_model = enc_key_dim , kernel_size = conv_kernel_size )
131
+ self .conv_module = _ConformerConvBlock (dim_model = enc_key_dim , kernel_size = conv_kernel_size )
132
132
133
- self .mhsa_module = MultiheadAttention (d_model , att_n_heads , dropout = att_dropout ) # TODO: to be implemented
133
+ self .mhsa_module = self . conv_module # MultiheadAttention(enc_key_dim, num_heads , dropout=att_dropout) # TODO: to be implemented
134
134
135
135
def forward (self , inp : LayerRef ) -> LayerRef :
136
136
# FFN
@@ -163,8 +163,8 @@ class ConformerEncoder(nn.Module):
163
163
"""
164
164
165
165
def __init__ (self , encoder_layer : nn .Module , num_blocks : int , conv_kernel_size : Tuple [int , ...] = (32 ,),
166
- ff_act = nn .swish , ff_dim : int = 512 , dropout : float = 0.1 , att_dropout : float = 0.1 , enc_key_dim : int = 256 ,
167
- att_n_heads : int = 4 , l2 : float = 0.0 ):
166
+ activation_ff = nn .swish , dim_ff : int = 512 , dropout : float = 0.1 , att_dropout : float = 0.1 , enc_key_dim : int = 256 ,
167
+ num_heads : int = 4 , l2 : float = 0.0 ):
168
168
"""
169
169
:param encoder_layer:
170
170
:param num_blocks:
@@ -189,8 +189,8 @@ def __init__(self, encoder_layer: nn.Module, num_blocks: int, conv_kernel_size:
189
189
190
190
self .conformer_blocks = nn .Sequential ([
191
191
encoder_layer (
192
- conv_kernel_size = conv_kernel_size , ff_act = ff_act , ff_dim = ff_dim , dropout = dropout ,
193
- att_dropout = att_dropout , enc_key_dim = enc_key_dim , att_n_heads = att_n_heads , l2 = l2
192
+ conv_kernel_size = conv_kernel_size , activation_ff = activation_ff , dim_ff = dim_ff , dropout = dropout ,
193
+ att_dropout = att_dropout , enc_key_dim = enc_key_dim , num_heads = num_heads , l2 = l2
194
194
)
195
195
for _ in range (num_blocks )
196
196
])
@@ -200,4 +200,4 @@ def forward(self, inp: LayerRef) -> LayerRef:
200
200
x_linear = self .linear (x_subsample )
201
201
x = nn .dropout (x_linear , dropout = self .dropout )
202
202
x = self .conformer_blocks (x )
203
- return x
203
+ return x
0 commit comments