class_docstr: VC Transformer module.
  
  This is a module of the Voice Transformer Network
  (a.k.a. VTN or Transformer-VC) described in
  `Voice Transformer Network: Sequence-to-Sequence
  Voice Conversion Using Transformer with
  Text-to-Speech Pretraining`_,
  which convert the sequence of acoustic features
  into the sequence of acoustic features.
  
  .. _`Voice Transformer Network: Sequence-to-Sequence
      Voice Conversion Using Transformer with
      Text-to-Speech Pretraining`:
      https://arxiv.org/pdf/1912.06813.pdf
class_docstr_tok: ["VC","Transformer","module",".","This","is","a","module","of","the","Voice","Transformer","Network","(","a.k.a",".","VTN","or","Transformer-VC",")","described","in","`","Voice","Transformer","Network",":","Sequence-to-Sequence","Voice","Conversion","Using","Transformer","with","Text-to-Speech","Pretraining","`","_",",","which","convert","the","sequence","of","acoustic","features","into","the","sequence","of","acoustic","features",".","..","_","`","Voice","Transformer","Network",":","Sequence-to-Sequence","Voice","Conversion","Using","Transformer","with","Text-to-Speech","Pretraining","`",":","https",":","\/\/arxiv.org\/pdf\/1912.06813.pdf"]
docstr: Generate the sequence of features given the sequences of acoustic features.
  
  Args:
      x (Tensor): Input sequence of acoustic features (T, idim).
      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","acoustic","features",".","Args",":","x","(","Tensor",")",":","Input","sequence","of","acoustic","features","(","T",",","idim",")",".","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 acoustic features.
  
      Args:
          x (Tensor): Input sequence of acoustic features (T, idim).
          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."
          )
  
      # thin out input frames for reduction factor
      # (B, Lmax, idim) ->  (B, Lmax // r, idim * r)
      if self.encoder_reduction_factor > 1:
          Lmax, idim = x.shape
          if Lmax % self.encoder_reduction_factor != 0:
              x = x[: -(Lmax % self.encoder_reduction_factor), :]
          x_ds = x.contiguous().view(
              int(Lmax / self.encoder_reduction_factor),
              idim * self.encoder_reduction_factor,
          )
      else:
          x_ds = x
  
      # forward encoder
      x_ds = x_ds.unsqueeze(0)
      hs, _ = self.encoder(x_ds, 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_asr_transformer import subsequent_mask
  from espnet.nets.pytorch_backend.e2e_tts_tacotron2 import Tacotron2Loss
  from espnet.nets.pytorch_backend.e2e_tts_transformer import TTSPlot
  from espnet.nets.pytorch_backend.e2e_tts_transformer import GuidedMultiHeadAttentionLoss
  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.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