Layer normalization module. :param int nout: output dim size :param int dim: dimension to be normalized
| 35 | # fastspeech modules |
| 36 | ###################### |
| 37 | class LayerNorm(torch.nn.LayerNorm): |
| 38 | """Layer normalization module. |
| 39 | :param int nout: output dim size |
| 40 | :param int dim: dimension to be normalized |
| 41 | """ |
| 42 | |
| 43 | def __init__(self, nout, dim=-1): |
| 44 | """Construct an LayerNorm object.""" |
| 45 | super(LayerNorm, self).__init__(nout, eps=1e-12) |
| 46 | self.dim = dim |
| 47 | |
| 48 | def forward(self, x): |
| 49 | """Apply layer normalization. |
| 50 | :param torch.Tensor x: input tensor |
| 51 | :return: layer normalized tensor |
| 52 | :rtype torch.Tensor |
| 53 | """ |
| 54 | if self.dim == -1: |
| 55 | return super(LayerNorm, self).forward(x) |
| 56 | return super(LayerNorm, self).forward(x.transpose(1, -1)).transpose(1, -1) |
| 57 | |
| 58 | |
| 59 | class DurationPredictor(torch.nn.Module): |