conv2d
Author: Heli Qi Affiliation: NAIST Date: 2022.07
Conv2dPrenet
Bases: Module
The Conv2d prenet. Usually used before the ASR encoder. This prenet is made up of two parts: 1. (mandatory) The Conv2d part contains one or more Conv2d blocks which are composed of the components below 1. (mandatory) a Conv2d layer 2. (optional) a BatchNorm2d layer 3. (optional) an activation function 4. (optional) a Dropout layer 2. (optional) The Linear part contains one or more Linear blocks which are composed of the components below 1. (mandatory) a Linear layer 2. (optional) an activation function 3. (optional) a Dropout layer.
Reference
Speech-transformer: a no-recurrence sequence-to-sequence model for speech recognition https://ieeexplore.ieee.org/abstract/document/8462506/
Source code in speechain/module/prenet/conv2d.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
|
forward(feat, feat_len)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feat
|
Tensor
|
(batch, feat_maxlen, feat_dim) The input acoustic feature tensors. |
required |
feat_len
|
Tensor
|
(batch,) The length of each acoustic feature tensor. |
required |
Returns:
Type | Description |
---|---|
The embedded feature vectors with their lengths. |
Source code in speechain/module/prenet/conv2d.py
module_init(feat_dim=None, conv_dims=[64, 64], conv_kernel=3, conv_stride=2, conv_padding=0, conv_batchnorm=False, conv_activation='ReLU', conv_dropout=None, lnr_dims=512, lnr_activation=None, lnr_dropout=None, zero_centered=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
feat_dim
|
int
|
int The dimension of input acoustic feature tensors. Used for calculating the in_features of the first Linear layer. |
None
|
conv_dims
|
int or List[int]
|
List[int] or int The values of out_channels of each Conv2d layer. If a list of integers is given, multiple Conv2d layers will be initialized. If an integer is given, there will be only one Conv2d layer |
[64, 64]
|
conv_kernel
|
int or List[int]
|
int or List[int] The value of kernel_size of all Conv2d layers. An integer means the same kernel size for time and frequency dimension. List[int] is needed if you would like to make different dimensions have different kernel sizes. |
3
|
conv_stride
|
int or List[int]
|
int or List[int] The value of stride of all Conv2d layers. An integer means the same stride for time and frequency dimension. List[int] is needed if you would like to make different dimensions have different strides. |
2
|
conv_padding
|
int or List[int]
|
int or List[int] The padding added to all four sides of the input. It can be either a string {‘valid’, ‘same’} or a list of integers giving the amount of implicit padding applied on both sides. |
0
|
conv_batchnorm
|
bool
|
bool Whether a BatchNorm2d layer is added after each Conv2d layer |
False
|
conv_activation
|
str
|
str The type of the activation function after all Conv2d layers. None means no activation function is needed. |
'ReLU'
|
conv_dropout
|
float or List[float]
|
float or List[float] The values of p rate of the Dropout layer after each Linear layer. |
None
|
lnr_dims
|
int or List[int]
|
int or List[int] The values of out_features of each Linear layer. The first value in the List represents the out_features of the first Linear layer. |
512
|
lnr_activation
|
str
|
str The type of the activation function after all Linear layers. None means no activation function is needed. For transformer training, it's better not to add a non-negative ReLU activation function to the last linear layer because the ReLU activation will make the range of the output (>= 0) different from the sinusoidal positional encoding [-1, 1]. For more details, please refer to Section 3.3 of the paper below: 'Neural Speech Synthesis with Transformer Network' https://ojs.aaai.org/index.php/AAAI/article/view/4642/4520 |
None
|
lnr_dropout
|
float or List[float]
|
float or List[float] The values of p rate of the Dropout layer after each Linear layer. |
None
|
zero_centered
|
bool
|
bool Whether the output of this module is centered at 0. If the specified activation function changes the centroid of the output distribution, e.g. ReLU and LeakyReLU, the activation function won't be attached to the final Linear layer if zer_centered is set to True. |
False
|
Source code in speechain/module/prenet/conv2d.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
|