espnet2.asr.decoder.transducer_decoder.TransducerDecoder
espnet2.asr.decoder.transducer_decoder.TransducerDecoder
class espnet2.asr.decoder.transducer_decoder.TransducerDecoder(vocab_size: int, rnn_type: str = 'lstm', num_layers: int = 1, hidden_size: int = 320, dropout: float = 0.0, dropout_embed: float = 0.0, embed_pad: int = 0)
Bases: AbsDecoder
(RNN-)Transducer decoder module.
- Parameters:
- vocab_size – Output dimension.
- layers_type – (RNN-)Decoder layers type.
- num_layers – Number of decoder layers.
- hidden_size – Number of decoder units per layer.
- dropout – Dropout rate for decoder layers.
- dropout_embed – Dropout rate for embedding layer.
- embed_pad – Embed/Blank symbol ID.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
batch_score(hyps: List[Hypothesis] | List[ExtendedHypothesis], dec_states: Tuple[Tensor, Tensor | None], cache: Dict[str, Any], use_lm: bool) → Tuple[Tensor, Tuple[Tensor, Tensor], Tensor]
One-step forward hypotheses.
- Parameters:
- hyps – Hypotheses.
- states – Decoder hidden states. ((N, B, D_dec), (N, B, D_dec))
- cache – Pairs of (dec_out, dec_states) for each label sequences. (keys)
- use_lm – Whether to compute label ID sequences for LM.
- Returns: Decoder output sequences. (B, D_dec) dec_states: Decoder hidden states. ((N, B, D_dec), (N, B, D_dec)) lm_labels: Label ID sequences for LM. (B,)
- Return type: dec_out
create_batch_states(states: Tuple[Tensor, Tensor | None], new_states: List[Tuple[Tensor, Tensor | None]], check_list: List | None = None) → List[Tuple[Tensor, Tensor | None]]
Create decoder hidden states.
- Parameters:
- states – Decoder hidden states. ((N, B, D_dec), (N, B, D_dec))
- new_states – Decoder hidden states. [N x ((1, D_dec), (1, D_dec))]
- Returns: Decoder hidden states. ((N, B, D_dec), (N, B, D_dec))
- Return type: states
forward(labels: Tensor) → Tensor
Encode source label sequences.
- Parameters:labels – Label ID sequences. (B, L)
- Returns: Decoder output sequences. (B, T, U, D_dec)
- Return type: dec_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))
rnn_forward(sequence: Tensor, state: Tuple[Tensor, Tensor | None]) → Tuple[Tensor, Tuple[Tensor, Tensor | None]]
Encode source label sequences.
- Parameters:
- sequence – RNN input sequences. (B, D_emb)
- state – Decoder hidden states. ((N, B, D_dec), (N, B, D_dec))
- Returns: RNN output sequences. (B, D_dec) (h_next, c_next): Decoder hidden states. (N, B, D_dec), (N, B, D_dec))
- Return type: sequence
score(hyp: Hypothesis, cache: Dict[str, Any]) → Tuple[Tensor, Tuple[Tensor, Tensor | None], Tensor]
One-step forward hypothesis.
- Parameters:
- hyp – Hypothesis.
- cache – Pairs of (dec_out, state) for each label sequence. (key)
- Returns: Decoder output sequence. (1, D_dec) new_state: Decoder hidden states. ((N, 1, D_dec), (N, 1, D_dec)) label: Label ID for LM. (1,)
- Return type: dec_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))
- idx – State ID to extract.
- Returns: Decoder hidden state for given ID. : ((N, 1, D_dec), (N, 1, D_dec))
set_device(device: device)
Set GPU device to use.
- Parameters:device – Device ID.