espnet2.asr_transducer.decoder.abs_decoder.AbsDecoder
espnet2.asr_transducer.decoder.abs_decoder.AbsDecoder
class espnet2.asr_transducer.decoder.abs_decoder.AbsDecoder(*args, **kwargs)
Bases: Module
, ABC
Abstract decoder module.
Initializes internal Module state, shared by both nn.Module and ScriptModule.
abstract batch_score(hyps: List[Any]) → Tuple[Tensor, List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, Tensor | None]]
One-step forward hypotheses.
- Parameters:hyps – Hypotheses.
- Returns: Decoder output sequences. states: Decoder hidden states.
- Return type: out
abstract create_batch_states(new_states: List[List[Dict[str, Tensor | None]] | List[List[Tensor]] | Tuple[Tensor, Tensor | None]]) → List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, Tensor | None]
Create batch of decoder hidden states given a list of new states.
- Parameters:new_states – Decoder hidden states.
- Returns: Decoder hidden states.
abstract forward(labels: Tensor) → Tensor
Encode source label sequences.
- Parameters:labels – Label ID sequences.
- Returns: Decoder output sequences.
abstract init_state(batch_size: int) → List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, tensor | None]
Initialize decoder states.
- Parameters:batch_size – Batch size.
- Returns: Decoder hidden states.
abstract score(label_sequence: List[int], states: List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, Tensor | None]) → Tuple[Tensor, List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, Tensor | None]]
One-step forward hypothesis.
- Parameters:
- label_sequence – Current label sequence.
- state – Decoder hidden states.
- Returns: Decoder output sequence. state: Decoder hidden states.
- Return type: out
abstract select_state(states: List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, Tensor | None], idx: int = 0) → List[Dict[str, Tensor]] | List[Tensor] | Tuple[Tensor, Tensor | None]
Get specified ID state from batch of states, if provided.
- Parameters:
- states – Decoder hidden states.
- idx – State ID to extract.
- Returns: Decoder hidden state for given ID.
abstract set_device(device: Tensor) → None
Set GPU device to use.
- Parameters:device – Device ID.