espnet2.lm.espnet_model_multitask.ESPnetMultitaskLanguageModel
espnet2.lm.espnet_model_multitask.ESPnetMultitaskLanguageModel
class espnet2.lm.espnet_model_multitask.ESPnetMultitaskLanguageModel(lm: AbsLM, vocab_size: int, token_list: Tuple[str, ...] | List[str], ignore_id: int = 0, lsm_weight: float = 0.0, length_normalized_loss: bool = False, sos_syms: List[str] = ['<generatetext>', '<generatespeech>'], eos_sym: str = '<sos/eos>')
Bases: AbsESPnetModel
Initializes internal Module state, shared by both nn.Module and ScriptModule.
batchify_nll(text: Tensor, text_lengths: Tensor, batch_size: int = 100) → Tuple[Tensor, Tensor]
Compute negative log likelihood(nll) from transformer language model
To avoid OOM, this fuction seperate the input into batches. Then call nll for each batch and combine and return results. :param text: (Batch, Length) :param text_lengths: (Batch,) :param batch_size: int, samples each batch contain when computing nll,
you may change this to avoid OOM or increase
collect_feats(text: Tensor, text_lengths: Tensor, **kwargs) → Dict[str, Tensor]
forward(text: Tensor, text_lengths: Tensor, **kwargs) → Tuple[Tensor, Dict[str, Tensor], Tensor]
Defines the computation performed at every call.
Should be overridden by all subclasses.
NOTE
Although the recipe for forward pass needs to be defined within this function, one should call the Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
nll(text: Tensor, text_lengths: Tensor, max_length: int | None = None) → Tuple[Tensor, Tensor]
Compute negative log likelihood (nll)
NOTE(yifan): We only use nll to calculate perplexity, : so there is no condition in each sentence.
Normally, this function is called in batchify_nll. :param text: (Batch, Length) :param text_lengths: (Batch,) :param max_lengths: int