diff options
Diffstat (limited to 'text_recognizer/networks/conformer/ff.py')
-rw-r--r-- | text_recognizer/networks/conformer/ff.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/text_recognizer/networks/conformer/ff.py b/text_recognizer/networks/conformer/ff.py new file mode 100644 index 0000000..2ef4245 --- /dev/null +++ b/text_recognizer/networks/conformer/ff.py @@ -0,0 +1,19 @@ +"""Conformer feedforward block.""" +from torch import nn, Tensor + + +class Feedforward(nn.Module): + def __init__( + self, dim: int, expansion_factor: int = 4, dropout: float = 0.0 + ) -> None: + super().__init__() + self.layers = nn.Sequential( + nn.Linear(dim, expansion_factor * dim), + nn.Mish(inplace=True), + nn.Dropout(dropout), + nn.Linear(expansion_factor * dim, dim), + nn.Dropout(dropout), + ) + + def forward(self, x: Tensor) -> Tensor: + return self.layers(x) |