espnet2.legacy.nets.pytorch_backend.transducer.custom_decoder.CustomDecoder
espnet2.legacy.nets.pytorch_backend.transducer.custom_decoder.CustomDecoder
class espnet2.legacy.nets.pytorch_backend.transducer.custom_decoder.CustomDecoder(odim: int, dec_arch: List, input_layer: str = 'embed', repeat_block: int = 0, joint_activation_type: str = 'tanh', positional_encoding_type: str = 'abs_pos', positionwise_layer_type: str = 'linear', positionwise_activation_type: str = 'relu', input_layer_dropout_rate: float = 0.0, blank_id: int = 0)
Bases: TransducerDecoderInterface, Module
Custom decoder module for Transducer model.
- Parameters:
- odim β Output dimension.
- dec_arch β Decoder block architecture (type and parameters).
- input_layer β Input layer type.
- repeat_block β Number of times dec_arch is repeated.
- joint_activation_type β Type of activation for joint network.
- positional_encoding_type β Positional encoding type.
- positionwise_layer_type β Positionwise layer type.
- positionwise_activation_type β Positionwise activation type.
- input_layer_dropout_rate β Dropout rate for input layer.
- blank_id β Blank symbol ID.
Construct a CustomDecoder object.
batch_score(hyps: List[Hypothesis] | List[ExtendedHypothesis], dec_states: List[Tensor | None], cache: Dict[str, Any], use_lm: bool) β Tuple[Tensor, List[Tensor | None], Tensor]
One-step forward hypotheses.
- Parameters:
- hyps β Hypotheses.
- dec_states β Decoder hidden states. [N x (B, U, D_dec)]
- cache β Pairs of (h_dec, 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 x (B, U, D_dec)] lm_labels: Label ID sequences for LM. (B,)
- Return type: dec_out
create_batch_states(states: List[Tensor | None], new_states: List[Tensor | None], check_list: List[List[int]]) β List[Tensor | None]
Create decoder hidden states sequences.
- Parameters:
- states β Decoder hidden states. [N x (B, U, D_dec)]
- new_states β Decoder hidden states. [B x [N x (1, U, D_dec)]]
- check_list β Label ID sequences.
- Returns: New decoder hidden states. [N x (B, U, D_dec)]
- Return type: states
forward(dec_input: Tensor, dec_mask: Tensor) β Tuple[Tensor, Tensor]
Encode label ID sequences.
- Parameters:
- dec_input β Label ID sequences. (B, U)
- dec_mask β Label mask sequences. (B, U)
- Returns: Decoder output sequences. (B, U, D_dec) dec_output_mask: Mask of decoder output sequences. (B, U)
- Return type: dec_output
init_state(batch_size: int | None = None) β List[Tensor | None]
Initialize decoder states.
- Parameters:batch_size β Batch size.
- Returns: Initial decoder hidden states. [N x None]
- Return type: state
score(hyp: Hypothesis, cache: Dict[str, Any]) β Tuple[Tensor, List[Tensor | None], Tensor]
One-step forward hypothesis.
- Parameters:
- hyp β Hypothesis.
- cache β Pairs of (dec_out, dec_state) for each label sequence. (key)
- Returns: Decoder output sequence. (1, D_dec) dec_state: Decoder hidden states. [N x (1, U, D_dec)] lm_label: Label ID for LM. (1,)
- Return type: dec_out
select_state(states: List[Tensor | None], idx: int) β List[Tensor | None]
Get specified ID state from decoder hidden states.
- Parameters:
- states β Decoder hidden states. [N x (B, U, D_dec)]
- idx β State ID to extract.
- Returns: Decoder hidden state for given ID. [N x (1, U, D_dec)]
- Return type: state_idx
set_device(device: device)
Set GPU device to use.
- Parameters:device β Device ID.
