espnet.nets.lm_interface.LMInterface
Less than 1 minute
espnet.nets.lm_interface.LMInterface
class espnet.nets.lm_interface.LMInterface
Bases: ScorerInterface
LM Interface for ESPnet model implementation.
static add_arguments(parser)
Add arguments to command line argument parser.
classmethod build(n_vocab: int, **kwargs)
Initialize this class with python-level args.
- Parameters:idim (int) – The number of vocabulary.
- Returns: A new instance of LMInterface.
- Return type: LMinterface
forward(x, t)
Compute LM loss value from buffer sequences.
- Parameters:
- x (torch.Tensor) – Input ids. (batch, len)
- t (torch.Tensor) – Target ids. (batch, len)
- Returns: Tuple of : loss to backward (scalar), negative log-likelihood of t: -log p(t) (scalar) and the number of elements in x (scalar)
- Return type: tuple[torch.Tensor, torch.Tensor, torch.Tensor]
Notes
The last two return values are used in perplexity: p(t)^{-n} = exp(-log p(t) / n)