class_docstr: Effective Use of Variational Embedding Capacity for prosody transfer.
  
  See https://arxiv.org/abs/1906.03402
class_docstr_tok: ["Effective","Use","of","Variational","Embedding","Capacity","for","prosody","transfer",".","See","https",":","\/\/arxiv.org\/abs\/1906.03402"]
code: def forward(
      self,
      reference_mel_info=None,
      text_info=None,
      speaker_embedding=None,
  ):
      # Use reference
      if reference_mel_info is not None:
          reference_mels = reference_mel_info[
              0
          ]  # [batch_size, num_frames, num_mels]
          mel_lengths = reference_mel_info[1]  # [batch_size]
          enc_out = self.encoder(reference_mels, mel_lengths)
  
          # concat speaker_embedding and/or text summary embedding
          if text_info is not None:
              text_inputs = text_info[
                  0
              ]  # [batch_size, num_characters, num_embedding]
              input_lengths = text_info[1]
              text_summary_out = self.text_summary_net(
                  text_inputs, input_lengths
              ).to(reference_mels.device)
              enc_out = torch.cat([enc_out, text_summary_out], dim=-1)
          if speaker_embedding is not None:
              speaker_embedding = torch.squeeze(speaker_embedding)
              enc_out = torch.cat([enc_out, speaker_embedding], dim=-1)
  
          # Feed the output of the ref encoder and information about text/speaker into
          # an MLP to produce the parameteres for the approximate poterior distributions
          mu, sigma = self.post_encoder_mlp(enc_out)
          # convert to cpu because prior_distribution was created on cpu
          mu = mu.cpu()
          sigma = sigma.cpu()
  
          # Sample from the posterior: z ~ q(z|x)
          self.approximate_posterior_distribution = MVN(
              mu, torch.diag_embed(sigma)
          )
          VAE_embedding = (
              self.approximate_posterior_distribution.rsample()
          )
      # Infer from the model, bypasses encoding
      else:
          # Sample from the prior: z ~ p(z)
          VAE_embedding = self.prior_distribution.sample().unsqueeze(0)
  
      # reshape to [batch_size, 1, capacitron_VAE_embedding_dim]
      return (
          VAE_embedding.unsqueeze(1),
          self.approximate_posterior_distribution,
          self.prior_distribution,
          self.beta,
      )
  
imports: import torch
  from torch import nn
  from torch.distributions.multivariate_normal import MultivariateNormal
  from torch.nn import functional
label_desc: Use image node_id 2 for calling the CapacitronVAE obj's underlying member method code with example usage: obj.forward(reference_mel_info, text_info, speaker_embedding) and returns: VAE_embedding,  self,  self,  self