class_docstr: TTranslatotron Synthesizer related modules for speech-to-speech translation.
  
  This is a module of Spectrogram prediction network in Translatotron described
  in `Direct speech-to-speech translation with a sequence-to-sequence model`_,
  which converts the sequence of hidden states into the sequence of Mel-filterbanks.
  
  .. _`Direct speech-to-speech translation with a sequence-to-sequence model`:
     https://arxiv.org/pdf/1904.06037.pdf
class_docstr_tok: ["TTranslatotron","Synthesizer","related","modules","for","speech-to-speech","translation",".","This","is","a","module","of","Spectrogram","prediction","network","in","Translatotron","described","in","`","Direct","speech-to-speech","translation","with","a","sequence-to-sequence","model","`","_",",","which","converts","the","sequence","of","hidden","states","into","the","sequence","of","Mel-filterbanks",".","..","_","`","Direct","speech-to-speech","translation","with","a","sequence-to-sequence","model","`",":","https",":","\/\/arxiv.org\/pdf\/1904.06037.pdf"]
docstr: Calculate forward propagation.
  
  Args:
      enc_outputs (LongTensor): Batch of padded character ids (B, T, idim).
      enc_outputs_lengths (LongTensor): Batch of lengths of each input batch (B,).
      feats (Tensor): Batch of padded target features (B, T_feats, odim).
      feats_lengths (LongTensor): Batch of the lengths of each target (B,).
      spembs (Optional[Tensor]): Batch of speaker embeddings (B, spk_embed_dim).
      sids (Optional[Tensor]): Batch of speaker IDs (B, 1).
      lids (Optional[Tensor]): Batch of language IDs (B, 1).
  
  Returns:
      after_outs (TODO(jiatong) add full comment)
      before_outs (TODO(jiatong) add full comments)
      logits
      att_ws
      ys
      stop_labels
      olens
docstr_tok: ["Calculate","forward","propagation",".","Args",":","enc_outputs","(","LongTensor",")",":","Batch","of","padded","character","ids","(","B",",","T",",","idim",")",".","enc_outputs_lengths","(","LongTensor",")",":","Batch","of","lengths","of","each","input","batch","(","B",",",")",".","feats","(","Tensor",")",":","Batch","of","padded","target","features","(","B",",","T_feats",",","odim",")",".","feats_lengths","(","LongTensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","spembs","(","Optional","[","Tensor","]",")",":","Batch","of","speaker","embeddings","(","B",",","spk_embed_dim",")",".","sids","(","Optional","[","Tensor","]",")",":","Batch","of","speaker","IDs","(","B",",","1",")",".","lids","(","Optional","[","Tensor","]",")",":","Batch","of","language","IDs","(","B",",","1",")",".","Returns",":","after_outs","(","TODO","(","jiatong",")","add","full","comment",")","before_outs","(","TODO","(","jiatong",")","add","full","comments",")","logits","att_ws","ys","stop_labels","olens"]
code: def forward(
      self,
      enc_outputs: torch.Tensor,
      enc_outputs_lengths: torch.Tensor,
      feats: torch.Tensor,
      feats_lengths: torch.Tensor,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
  ) -> Tuple[torch.Tensor, torch.Tensor]:
      """Calculate forward propagation.
  
      Args:
          enc_outputs (LongTensor): Batch of padded character ids (B, T, idim).
          enc_outputs_lengths (LongTensor): Batch of lengths of each input batch (B,).
          feats (Tensor): Batch of padded target features (B, T_feats, odim).
          feats_lengths (LongTensor): Batch of the lengths of each target (B,).
          spembs (Optional[Tensor]): Batch of speaker embeddings (B, spk_embed_dim).
          sids (Optional[Tensor]): Batch of speaker IDs (B, 1).
          lids (Optional[Tensor]): Batch of language IDs (B, 1).
  
      Returns:
          after_outs (TODO(jiatong) add full comment)
          before_outs (TODO(jiatong) add full comments)
          logits
          att_ws
          ys
          stop_labels
          olens
      """
  
      enc_outputs = enc_outputs[:, : enc_outputs_lengths.max()]
      feats = feats[:, : feats_lengths.max()]  # for data-parallel
  
      ys = feats
      olens = feats_lengths
  
      # make labels for stop prediction
      labels = make_pad_mask(olens - 1).to(ys.device, ys.dtype)
      labels = F.pad(labels, [0, 1], "constant", 1.0)
  
      # calculate tacotron2 outputs
      after_outs, before_outs, logits, att_ws = self._forward(
          hs=enc_outputs,
          hlens=enc_outputs_lengths,
          ys=ys,
          olens=olens,
          spembs=spembs,
          sids=sids,
          lids=lids,
      )
  
      # modify mod part of groundtruth
      if self.reduction_factor > 1:
          assert olens.ge(
              self.reduction_factor
          ).all(), "Output length must be greater than or equal to reduction factor."
          olens = olens.new(
              [olen - olen % self.reduction_factor for olen in olens]
          )
          max_out = max(olens)
          ys = ys[:, :max_out]
          labels = labels[:, :max_out]
          labels = torch.scatter(
              labels, 1, (olens - 1).unsqueeze(1), 1.0
          )  # see #3388
  
      return after_outs, before_outs, logits, att_ws, ys, labels, olens
  
file_path: espnet/espnet2/s2st/synthesizer/translatotron.py
imports: import logging
  from typing import Dict, Optional, Sequence, Tuple
  import torch
  import torch.nn.functional
  from typeguard import check_argument_types
  from espnet2.s2st.synthesizer.abs_synthesizer import AbsSynthesizer
  from espnet2.torch_utils.device_funcs import force_gatherable
  from espnet2.tts.gst.style_encoder import StyleEncoder
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import GuidedAttentionLoss, Tacotron2Loss
  from espnet.nets.pytorch_backend.nets_utils import make_pad_mask
  from espnet.nets.pytorch_backend.rnn.attentions import AttForward, AttForwardTA, AttLoc, AttMultiHeadAdd
  from espnet.nets.pytorch_backend.tacotron2.decoder import Decoder
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
label_desc: Use image node_id 2 for calling the Translatotron obj's underlying member method code with example usage: obj.forward(enc_outputs, enc_outputs_lengths, feats, feats_lengths, spembs, sids, lids) and returns: after_outs,  before_outs,  logits,  att_ws,  ys,  labels,  olens