espnet2.asr_transducer.decoder.rnn_decoder.RNNDecoder
espnet2.asr_transducer.decoder.rnn_decoder.RNNDecoder
class espnet2.asr_transducer.decoder.rnn_decoder.RNNDecoder(vocab_size: int, embed_size: int = 256, hidden_size: int = 256, rnn_type: str = 'lstm', num_layers: int = 1, dropout_rate: float = 0.0, embed_dropout_rate: float = 0.0, embed_pad: int = 0)
Bases: AbsDecoder
RNN decoder module.
- Parameters:
- vocab_size – Vocabulary size.
- embed_size – Embedding size.
- hidden_size – Hidden size..
- rnn_type – Decoder layers type.
- num_layers – Number of decoder layers.
- dropout_rate – Dropout rate for decoder layers.
- embed_dropout_rate – Dropout rate for embedding layer.
- embed_pad – Embedding padding symbol ID.
Construct a RNNDecoder object.
batch_score(hyps: List[Hypothesis]) → Tuple[Tensor, Tuple[Tensor, Tensor | None]]
One-step forward hypotheses.
- Parameters:hyps – Hypotheses.
- Returns: Decoder output sequences. (B, D_dec) states: Decoder hidden states. ((N, B, D_dec), (N, B, D_dec) or None)
- Return type: out
create_batch_states(new_states: List[Tuple[Tensor, Tensor | None]]) → Tuple[Tensor, Tensor | None]
Create decoder hidden states.
- Parameters:new_states – Decoder hidden states. [B x ((N, 1, D_dec), (N, 1, D_dec) or None)]
- Returns: Decoder hidden states. ((N, B, D_dec), (N, B, D_dec) or None)
- Return type: states
forward(labels: Tensor) → Tensor
Encode source label sequences.
- Parameters:labels – Label ID sequences. (B, L)
- Returns: Decoder output sequences. (B, U, D_dec)
- Return type: out
init_state(batch_size: int) → Tuple[Tensor, tensor | None]
Initialize decoder states.
- Parameters:batch_size – Batch size.
- Returns: Initial decoder hidden states. ((N, B, D_dec), (N, B, D_dec) or None)
rnn_forward(x: Tensor, state: Tuple[Tensor, Tensor | None]) → Tuple[Tensor, Tuple[Tensor, Tensor | None]]
Encode source label sequences.
- Parameters:
- x – RNN input sequences. (B, D_emb)
- state – Decoder hidden states. ((N, B, D_dec), (N, B, D_dec) or None)
- Returns: RNN output sequences. (B, D_dec) (h_next, c_next): Decoder hidden states.
(N, B, D_dec), (N, B, D_dec) or None)
- Return type: x
score(label_sequence: List[int], states: Tuple[Tensor, Tensor | None]) → Tuple[Tensor, Tuple[Tensor, Tensor | None]]
One-step forward hypothesis.
- Parameters:
- label_sequence – Current label sequence.
- states – Decoder hidden states. ((N, 1, D_dec), (N, 1, D_dec) or None)
- Returns: Decoder output sequence. (1, D_dec) states: Decoder hidden states.
((N, 1, D_dec), (N, 1, D_dec) or None)
- Return type: out
select_state(states: Tuple[Tensor, Tensor | None], idx: int) → Tuple[Tensor, Tensor | None]
Get specified ID state from decoder hidden states.
- Parameters:
- states – Decoder hidden states. ((N, B, D_dec), (N, B, D_dec) or None)
- idx – State ID to extract.
- Returns: Decoder hidden state for given ID. ((N, 1, D_dec), (N, 1, D_dec) or None)
set_device(device: device) → None
Set GPU device to use.
- Parameters:device – Device ID.