class_docstr: Alignment Learning Framework proposed for parallel TTS models in:
  
  https://arxiv.org/abs/2108.10447
class_docstr_tok: ["Alignment","Learning","Framework","proposed","for","parallel","TTS","models","in",":","https",":","\/\/arxiv.org\/abs\/2108.10447"]
docstr: Calculate alignment loss.
  
  Args:
      text (Tensor): Batched text embedding (B, T_text, adim).
      feats (Tensor): Batched acoustic feature (B, T_feats, odim).
      text_lengths (Tensor): Text length tensor (B,).
      feats_lengths (Tensor): Feature length tensor (B,).
      x_masks (Tensor): Mask tensor (B, T_text).
  
  Returns:
      Tensor: Log probability of attention matrix (B, T_feats, T_text).
docstr_tok: ["Calculate","alignment","loss",".","Args",":","text","(","Tensor",")",":","Batched","text","embedding","(","B",",","T_text",",","adim",")",".","feats","(","Tensor",")",":","Batched","acoustic","feature","(","B",",","T_feats",",","odim",")",".","text_lengths","(","Tensor",")",":","Text","length","tensor","(","B",",",")",".","feats_lengths","(","Tensor",")",":","Feature","length","tensor","(","B",",",")",".","x_masks","(","Tensor",")",":","Mask","tensor","(","B",",","T_text",")",".","Returns",":","Tensor",":","Log","probability","of","attention","matrix","(","B",",","T_feats",",","T_text",")","."]
code: def forward(
      self, text, feats, text_lengths, feats_lengths, x_masks=None
  ):
      """Calculate alignment loss.
  
      Args:
          text (Tensor): Batched text embedding (B, T_text, adim).
          feats (Tensor): Batched acoustic feature (B, T_feats, odim).
          text_lengths (Tensor): Text length tensor (B,).
          feats_lengths (Tensor): Feature length tensor (B,).
          x_masks (Tensor): Mask tensor (B, T_text).
  
      Returns:
          Tensor: Log probability of attention matrix (B, T_feats, T_text).
  
      """
      text = text.transpose(1, 2)
      text = F.relu(self.t_conv1(text))
      text = self.t_conv2(text)
      text = text.transpose(1, 2)
  
      feats = feats.transpose(1, 2)
      feats = F.relu(self.f_conv1(feats))
      feats = F.relu(self.f_conv2(feats))
      feats = self.f_conv3(feats)
      feats = feats.transpose(1, 2)
  
      dist = feats.unsqueeze(2) - text.unsqueeze(1)
      dist = torch.norm(dist, p=2, dim=3)
      score = -dist
  
      if x_masks is not None:
          x_masks = x_masks.unsqueeze(-2)
          score = score.masked_fill(x_masks, -np.inf)
  
      log_p_attn = F.log_softmax(score, dim=-1)
  
      # add beta-binomial prior
      bb_prior = self._generate_prior(
          text_lengths,
          feats_lengths,
      ).to(dtype=log_p_attn.dtype, device=log_p_attn.device)
      log_p_attn = log_p_attn + bb_prior
  
      return log_p_attn
  
file_path: espnet/espnet2/gan_tts/jets/alignments.py
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from numba import jit
  from scipy.stats import betabinom
label_desc: Use image node_id 2 for calling the AlignmentModule obj's underlying member method code with example usage: obj.forward(text, feats, text_lengths, feats_lengths, x_masks) and returns: log_p_attn