espnet2.lm.seq_rnn_lm.SequentialRNNLM
espnet2.lm.seq_rnn_lm.SequentialRNNLM
class espnet2.lm.seq_rnn_lm.SequentialRNNLM(vocab_size: int, unit: int = 650, nhid: int | None = None, nlayers: int = 2, dropout_rate: float = 0.0, tie_weights: bool = False, rnn_type: str = 'lstm', ignore_id: int = 0)
Bases: AbsLM
Sequential RNNLM.
SEE ALSO
Initializes internal Module state, shared by both nn.Module and ScriptModule.
batch_score(ys: Tensor, states: Tensor, xs: Tensor) → Tuple[Tensor, Tensor]
Score new token batch.
- Parameters:
- ys (torch.Tensor) – torch.int64 prefix tokens (n_batch, ylen).
- states (List *[*Any ]) – Scorer states for prefix tokens.
- xs (torch.Tensor) – The encoder feature that generates ys (n_batch, xlen, n_feat).
- Returns: Tuple of : batchfied scores for next token with shape of (n_batch, n_vocab) and next state list for ys.
- Return type: tuple[torch.Tensor, List[Any]]
forward(input: Tensor, hidden: Tensor) → Tuple[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.
score(y: Tensor, state: Tensor | Tuple[Tensor, Tensor], x: Tensor) → Tuple[Tensor, Tensor | Tuple[Tensor, Tensor]]
Score new token.
- Parameters:
- y – 1D torch.int64 prefix tokens.
- state – Scorer state for prefix tokens
- x – 2D encoder feature that generates ys.
- Returns: Tuple of : torch.float32 scores for next token (n_vocab) and next state for ys
zero_state()
Initialize LM state filled with zero values.