class_docstr: Text-to-Speech Transformer module.
  
  This is a module of text-to-speech Transformer described
  in `Neural Speech Synthesis with Transformer Network`_,
  which convert the sequence of characters
  or phonemes into the sequence of Mel-filterbanks.
  
  .. _`Neural Speech Synthesis with Transformer Network`:
      https://arxiv.org/pdf/1809.08895.pdf
class_docstr_tok: ["Text-to-Speech","Transformer","module",".","This","is","a","module","of","text-to-speech","Transformer","described","in","`","Neural","Speech","Synthesis","with","Transformer","Network","`","_",",","which","convert","the","sequence","of","characters","or","phonemes","into","the","sequence","of","Mel-filterbanks",".","..","_","`","Neural","Speech","Synthesis","with","Transformer","Network","`",":","https",":","\/\/arxiv.org\/pdf\/1809.08895.pdf"]
docstr: Generate the sequence of features given the sequences of characters.
  
  Args:
      x (Tensor): Input sequence of characters (T,).
      inference_args (Namespace):
          - threshold (float): Threshold in inference.
          - minlenratio (float): Minimum length ratio in inference.
          - maxlenratio (float): Maximum length ratio in inference.
      spemb (Tensor, optional): Speaker embedding vector (spk_embed_dim).
  
  Returns:
      Tensor: Output sequence of features (L, odim).
      Tensor: Output sequence of stop probabilities (L,).
      Tensor: Encoder-decoder (source) attention weights (#layers, #heads, L, T).
docstr_tok: ["Generate","the","sequence","of","features","given","the","sequences","of","characters",".","Args",":","x","(","Tensor",")",":","Input","sequence","of","characters","(","T",",",")",".","inference_args","(","Namespace",")",":","-","threshold","(","float",")",":","Threshold","in","inference",".","-","minlenratio","(","float",")",":","Minimum","length","ratio","in","inference",".","-","maxlenratio","(","float",")",":","Maximum","length","ratio","in","inference",".","spemb","(","Tensor",",","optional",")",":","Speaker","embedding","vector","(","spk_embed_dim",")",".","Returns",":","Tensor",":","Output","sequence","of","features","(","L",",","odim",")",".","Tensor",":","Output","sequence","of","stop","probabilities","(","L",",",")",".","Tensor",":","Encoder-decoder","(","source",")","attention","weights","(","#","layers",",","#","heads",",","L",",","T",")","."]
code: def inference(self, x, inference_args, spemb=None, *args, **kwargs):
      """Generate the sequence of features given the sequences of characters.
  
      Args:
          x (Tensor): Input sequence of characters (T,).
          inference_args (Namespace):
              - threshold (float): Threshold in inference.
              - minlenratio (float): Minimum length ratio in inference.
              - maxlenratio (float): Maximum length ratio in inference.
          spemb (Tensor, optional): Speaker embedding vector (spk_embed_dim).
  
      Returns:
          Tensor: Output sequence of features (L, odim).
          Tensor: Output sequence of stop probabilities (L,).
          Tensor: Encoder-decoder (source) attention weights (#layers, #heads, L, T).
  
      """
      # get options
      threshold = inference_args.threshold
      minlenratio = inference_args.minlenratio
      maxlenratio = inference_args.maxlenratio
      use_att_constraint = getattr(
          inference_args, "use_att_constraint", False
      )  # keep compatibility
      if use_att_constraint:
          logging.warning(
              "Attention constraint is not yet supported in Transformer. Not enabled."
          )
  
      # forward encoder
      xs = x.unsqueeze(0)
      hs, _ = self.encoder(xs, None)
  
      # integrate speaker embedding
      if self.spk_embed_dim is not None:
          spembs = spemb.unsqueeze(0)
          hs = self._integrate_with_spk_embed(hs, spembs)
  
      # set limits of length
      maxlen = int(hs.size(1) * maxlenratio / self.reduction_factor)
      minlen = int(hs.size(1) * minlenratio / self.reduction_factor)
  
      # initialize
      idx = 0
      ys = hs.new_zeros(1, 1, self.odim)
      outs, probs = [], []
  
      # forward decoder step-by-step
      z_cache = self.decoder.init_state(x)
      while True:
          # update index
          idx += 1
  
          # calculate output and stop prob at idx-th step
          y_masks = subsequent_mask(idx).unsqueeze(0).to(x.device)
          z, z_cache = self.decoder.forward_one_step(
              ys, y_masks, hs, cache=z_cache
          )  # (B, adim)
          outs += [
              self.feat_out(z).view(self.reduction_factor, self.odim)
          ]  # [(r, odim), ...]
          probs += [torch.sigmoid(self.prob_out(z))[0]]  # [(r), ...]
  
          # update next inputs
          ys = torch.cat(
              (ys, outs[-1][-1].view(1, 1, self.odim)), dim=1
          )  # (1, idx + 1, odim)
  
          # get attention weights
          att_ws_ = []
          for name, m in self.named_modules():
              if isinstance(m, MultiHeadedAttention) and "src" in name:
                  att_ws_ += [
                      m.attn[0, :, -1].unsqueeze(1)
                  ]  # [(#heads, 1, T),...]
          if idx == 1:
              att_ws = att_ws_
          else:
              # [(#heads, l, T), ...]
              att_ws = [
                  torch.cat([att_w, att_w_], dim=1)
                  for att_w, att_w_ in zip(att_ws, att_ws_)
              ]
  
          # check whether to finish generation
          if int(sum(probs[-1] >= threshold)) > 0 or idx >= maxlen:
              # check mininum length
              if idx < minlen:
                  continue
              outs = (
                  torch.cat(outs, dim=0).unsqueeze(0).transpose(1, 2)
              )  # (L, odim) -> (1, L, odim) -> (1, odim, L)
              if self.postnet is not None:
                  outs = outs + self.postnet(outs)  # (1, odim, L)
              outs = outs.transpose(2, 1).squeeze(0)  # (L, odim)
              probs = torch.cat(probs, dim=0)
              break
  
      # concatenate attention weights -> (#layers, #heads, L, T)
      att_ws = torch.stack(att_ws, dim=0)
  
      return outs, probs, att_ws
  
imports: import logging
  import torch
  import torch.nn.functional
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import GuidedAttentionLoss
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2Loss
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
  from espnet.nets.pytorch_backend.tacotron2.decoder import Postnet
  from espnet.nets.pytorch_backend.tacotron2.decoder import Prenet
  from espnet.nets.pytorch_backend.tacotron2.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.attention import MultiHeadedAttention
  from espnet.nets.pytorch_backend.transformer.decoder import Decoder
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding, ScaledPositionalEncoding
  from espnet.nets.pytorch_backend.transformer.encoder import Encoder
  from espnet.nets.pytorch_backend.transformer.initializer import initialize
  from espnet.nets.pytorch_backend.transformer.mask import subsequent_mask
  from espnet.nets.tts_interface import TTSInterface
  from espnet.utils.cli_utils import strtobool
  from espnet.utils.fill_missing_args import fill_missing_args
label_desc: Use image node_id 7 for calling the Transformer obj's underlying member method code with example usage: obj.inference(x, inference_args, spemb) and returns: outs,  probs,  att_ws