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: Generate the sequence of features given the sequences of characters.
  
  Args:
      enc_outputs (LongTensor): Input sequence of characters (N, idim).
      feats (Optional[Tensor]): Feature sequence to extract style (N, odim).
      spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
      sids (Optional[Tensor]): Speaker ID (1,).
      lids (Optional[Tensor]): Language ID (1,).
      threshold (float): Threshold in inference.
      minlenratio (float): Minimum length ratio in inference.
      maxlenratio (float): Maximum length ratio in inference.
      use_att_constraint (bool): Whether to apply attention constraint.
      backward_window (int): Backward window in attention constraint.
      forward_window (int): Forward window in attention constraint.
      use_teacher_forcing (bool): Whether to use teacher forcing.
  
  Returns:
      Dict[str, Tensor]: Output dict including the following items:
          * feat_gen (Tensor): Output sequence of features (T_feats, odim).
          * prob (Tensor): Output sequence of stop probabilities (T_feats,).
          * att_w (Tensor): Attention weights (T_feats, T).
docstr_tok: ["Generate","the","sequence","of","features","given","the","sequences","of","characters",".","Args",":","enc_outputs","(","LongTensor",")",":","Input","sequence","of","characters","(","N",",","idim",")",".","feats","(","Optional","[","Tensor","]",")",":","Feature","sequence","to","extract","style","(","N",",","odim",")",".","spembs","(","Optional","[","Tensor","]",")",":","Speaker","embedding","(","spk_embed_dim",",",")",".","sids","(","Optional","[","Tensor","]",")",":","Speaker","ID","(","1",",",")",".","lids","(","Optional","[","Tensor","]",")",":","Language","ID","(","1",",",")",".","threshold","(","float",")",":","Threshold","in","inference",".","minlenratio","(","float",")",":","Minimum","length","ratio","in","inference",".","maxlenratio","(","float",")",":","Maximum","length","ratio","in","inference",".","use_att_constraint","(","bool",")",":","Whether","to","apply","attention","constraint",".","backward_window","(","int",")",":","Backward","window","in","attention","constraint",".","forward_window","(","int",")",":","Forward","window","in","attention","constraint",".","use_teacher_forcing","(","bool",")",":","Whether","to","use","teacher","forcing",".","Returns",":","Dict","[","str",",","Tensor","]",":","Output","dict","including","the","following","items",":","*","feat_gen","(","Tensor",")",":","Output","sequence","of","features","(","T_feats",",","odim",")",".","*","prob","(","Tensor",")",":","Output","sequence","of","stop","probabilities","(","T_feats",",",")",".","*","att_w","(","Tensor",")",":","Attention","weights","(","T_feats",",","T",")","."]
code: def inference(
      self,
      enc_outputs: torch.Tensor,
      feats: Optional[torch.Tensor] = None,
      spembs: Optional[torch.Tensor] = None,
      sids: Optional[torch.Tensor] = None,
      lids: Optional[torch.Tensor] = None,
      threshold: float = 0.5,
      minlenratio: float = 0.0,
      maxlenratio: float = 10.0,
      use_att_constraint: bool = False,
      backward_window: int = 1,
      forward_window: int = 3,
      use_teacher_forcing: bool = False,
  ) -> Dict[str, torch.Tensor]:
      """Generate the sequence of features given the sequences of characters.
  
      Args:
          enc_outputs (LongTensor): Input sequence of characters (N, idim).
          feats (Optional[Tensor]): Feature sequence to extract style (N, odim).
          spembs (Optional[Tensor]): Speaker embedding (spk_embed_dim,).
          sids (Optional[Tensor]): Speaker ID (1,).
          lids (Optional[Tensor]): Language ID (1,).
          threshold (float): Threshold in inference.
          minlenratio (float): Minimum length ratio in inference.
          maxlenratio (float): Maximum length ratio in inference.
          use_att_constraint (bool): Whether to apply attention constraint.
          backward_window (int): Backward window in attention constraint.
          forward_window (int): Forward window in attention constraint.
          use_teacher_forcing (bool): Whether to use teacher forcing.
  
      Returns:
          Dict[str, Tensor]: Output dict including the following items:
              * feat_gen (Tensor): Output sequence of features (T_feats, odim).
              * prob (Tensor): Output sequence of stop probabilities (T_feats,).
              * att_w (Tensor): Attention weights (T_feats, T).
  
      """
      h = enc_outputs
      y = feats
      spemb = spembs
  
      # inference with teacher forcing
      if use_teacher_forcing:
          assert (
              feats is not None
          ), "feats must be provided with teacher forcing."
  
          hs, ys = h.unsqueeze(0), y.unsqueeze(0)
          spembs = None if spemb is None else spemb.unsqueeze(0)
          hlens = h.new_tensor([hs.size(1)]).long()
          olens = y.new_tensor([ys.size(1)]).long()
          outs, _, _, att_ws = self._forward(
              hs=hs,
              hlens=hlens,
              ys=ys,
              olens=olens,
              spembs=spembs,
              sids=sids,
              lids=lids,
          )
  
          return dict(feat_gen=outs[0], att_w=att_ws[0])
  
      # inference
      if self.spks is not None:
          sid_emb = self.sid_emb(sids.view(-1))
          enc_outputs = enc_outputs + sid_emb
      if self.langs is not None:
          lid_emb = self.lid_emb(lids.view(-1))
          enc_outputs = enc_outputs + lid_emb
      if self.spk_embed_dim is not None:
          enc_outputs, spembs = enc_outputs.unsqueeze(
              0
          ), spemb.unsqueeze(0)
          enc_outputs = self._integrate_with_spk_embed(
              enc_outputs, spembs
          )[0]
      out, prob, att_w = self.dec.inference(
          enc_outputs,
          threshold=threshold,
          minlenratio=minlenratio,
          maxlenratio=maxlenratio,
          use_att_constraint=use_att_constraint,
          backward_window=backward_window,
          forward_window=forward_window,
      )
  
      return dict(feat_gen=out, prob=prob, att_w=att_w)
  
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 4 for calling the Translatotron obj's underlying member method code with example usage: obj.inference(enc_outputs, feats, spembs, sids, lids, threshold, minlenratio, maxlenratio, use_att_constraint, backward_window, forward_window, use_teacher_forcing) and returns: dict, dict