Chong Zhang
2023-01-04 7836bee517a678192890a02449ef9aa7fe89f8fb
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
from abc import ABC
from abc import abstractmethod
from typing import Tuple
 
import torch
 
from funasr.modules.scorers.scorer_interface import BatchScorerInterface
 
 
class AbsLM(torch.nn.Module, BatchScorerInterface, ABC):
    """The abstract LM class
 
    To share the loss calculation way among different models,
    We uses delegate pattern here:
    The instance of this class should be passed to "LanguageModel"
 
    >>> from funasr.lm.abs_model import AbsLM
    >>> lm = AbsLM()
    >>> model = LanguageESPnetModel(lm=lm)
 
    This "model" is one of mediator objects for "Task" class.
 
    """
 
    @abstractmethod
    def forward(
        self, input: torch.Tensor, hidden: torch.Tensor
    ) -> Tuple[torch.Tensor, torch.Tensor]:
        raise NotImplementedError