jmwang66
2023-06-29 98abc0e5ac1a1da0fe1802d9ffb623802fbf0b2f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
#  2021, Carnegie Mellon University;  Xuankai Chang
#  Apache 2.0  (http://www.apache.org/licenses/LICENSE-2.0)
 
"""Linear Projection."""
 
from funasr.models.preencoder.abs_preencoder import AbsPreEncoder
from typing import Tuple
 
import torch
 
 
class LinearProjection(AbsPreEncoder):
    """Linear Projection Preencoder."""
 
    def __init__(
        self,
        input_size: int,
        output_size: int,
    ):
        """Initialize the module."""
        super().__init__()
 
        self.output_dim = output_size
        self.linear_out = torch.nn.Linear(input_size, output_size)
 
    def forward(
        self, input: torch.Tensor, input_lengths: torch.Tensor
    ) -> Tuple[torch.Tensor, torch.Tensor]:
        """Forward."""
        output = self.linear_out(input)
        return output, input_lengths  # no state in this layer
 
    def output_size(self) -> int:
        """Get the output size."""
        return self.output_dim