espnet2.asr.decoder.transformer_decoder.TransformerMDDecoder
espnet2.asr.decoder.transformer_decoder.TransformerMDDecoder
class espnet2.asr.decoder.transformer_decoder.TransformerMDDecoder(vocab_size: int, encoder_output_size: int, attention_heads: int = 4, linear_units: int = 2048, num_blocks: int = 6, dropout_rate: float = 0.1, positional_dropout_rate: float = 0.1, self_attention_dropout_rate: float = 0.0, src_attention_dropout_rate: float = 0.0, input_layer: str = 'embed', use_output_layer: bool = True, pos_enc_class=<class 'espnet.nets.pytorch_backend.transformer.embedding.PositionalEncoding'>, normalize_before: bool = True, concat_after: bool = False, use_speech_attn: bool = True)
Bases: BaseTransformerDecoder
Initializes internal Module state, shared by both nn.Module and ScriptModule.
batch_score(ys: Tensor, states: List[Any], xs: Tensor, speech: Tensor | None = None) → Tuple[Tensor, List[Any]]
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(hs_pad: Tensor, hlens: Tensor, ys_in_pad: Tensor, ys_in_lens: Tensor, speech: Tensor | None = None, speech_lens: Tensor | None = None, return_hs: bool = False) → Tuple[Tensor, Tensor]
Forward decoder.
Parameters:
- hs_pad – encoded memory, float32 (batch, maxlen_in, feat)
- hlens – (batch)
- ys_in_pad – input token ids, int64 (batch, maxlen_out) if input_layer == “embed” input tensor (batch, maxlen_out, #mels) in the other cases
- ys_in_lens – (batch)
- return_hs – dec hidden state corresponding to ys, used for searchable hidden ints
Returns: tuple containing:
x: decoded token score before softmax (batch, maxlen_out, token) : if use_output_layer is True,
olens: (batch, )
Return type: (tuple)
forward_one_step(tgt: Tensor, tgt_mask: Tensor, memory: Tensor, memory_mask: Tensor | None = None, *, speech: Tensor | None = None, speech_mask: Tensor | None = None, cache: List[Tensor] | None = None, return_hs: bool = False) → Tuple[Tensor, List[Tensor]]
Forward one step.
- Parameters:
- tgt – input token ids, int64 (batch, maxlen_out)
- tgt_mask – input token mask, (batch, maxlen_out) dtype=torch.uint8 in PyTorch 1.2- dtype=torch.bool in PyTorch 1.2+ (include 1.2)
- memory – encoded memory, float32 (batch, maxlen_in, feat)
- memory_mask – encoded memory mask (batch, 1, maxlen_in)
- speech – encoded speech, float32 (batch, maxlen_in, feat)
- speech_mask – encoded memory mask (batch, 1, maxlen_in)
- cache – cached output list of (batch, max_time_out-1, size)
- return_hs – dec hidden state corresponding to ys, used for searchable hidden ints
- Returns: NN output value and cache per self.decoders. y.shape` is (batch, maxlen_out, token)
- Return type: y, cache
score(ys, state, x, speech=None)
Score.