espnet2.lm.espnet_model.ESPnetLanguageModel
espnet2.lm.espnet_model.ESPnetLanguageModel
class espnet2.lm.espnet_model.ESPnetLanguageModel(lm: AbsLM, vocab_size: int, ignore_id: int = 0)
Bases: AbsESPnetModel
Initialize 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]
Define 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)
Normally, this function is called in batchify_nll. :param text: (Batch, Length) :param text_lengths: (Batch,) :param max_lengths: int
