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: Generate alignment prior formulated as beta-binomial distribution
  
  Args:
      text_lengths (Tensor): Batch of the lengths of each input (B,).
      feats_lengths (Tensor): Batch of the lengths of each target (B,).
      w (float): Scaling factor; lower -> wider the width.
  
  Returns:
      Tensor: Batched 2d static prior matrix (B, T_feats, T_text).
docstr_tok: ["Generate","alignment","prior","formulated","as","beta-binomial","distribution","Args",":","text_lengths","(","Tensor",")",":","Batch","of","the","lengths","of","each","input","(","B",",",")",".","feats_lengths","(","Tensor",")",":","Batch","of","the","lengths","of","each","target","(","B",",",")",".","w","(","float",")",":","Scaling","factor",";","lower","-",">","wider","the","width",".","Returns",":","Tensor",":","Batched","2d","static","prior","matrix","(","B",",","T_feats",",","T_text",")","."]
code: def _generate_prior(
      self, text_lengths, feats_lengths, w=1
  ) -> torch.Tensor:
      """Generate alignment prior formulated as beta-binomial distribution
  
      Args:
          text_lengths (Tensor): Batch of the lengths of each input (B,).
          feats_lengths (Tensor): Batch of the lengths of each target (B,).
          w (float): Scaling factor; lower -> wider the width.
  
      Returns:
          Tensor: Batched 2d static prior matrix (B, T_feats, T_text).
  
      """
      B = len(text_lengths)
      T_text = text_lengths.max()
      T_feats = feats_lengths.max()
  
      bb_prior = torch.full((B, T_feats, T_text), fill_value=-np.inf)
      for bidx in range(B):
          T = feats_lengths[bidx].item()
          N = text_lengths[bidx].item()
  
          key = str(T) + "," + str(N)
          if self.cache_prior and key in self._cache:
              prob = self._cache[key]
          else:
              alpha = w * np.arange(1, T + 1, dtype=float)  # (T,)
              beta = w * np.array([T - t + 1 for t in alpha])
              k = np.arange(N)
              batched_k = k[..., None]  # (N,1)
              prob = betabinom.logpmf(
                  batched_k, N, alpha, beta
              )  # (N,T)
  
          # store cache
          if self.cache_prior and key not in self._cache:
              self._cache[key] = prob
  
          prob = torch.from_numpy(prob).transpose(0, 1)  # -> (T,N)
          bb_prior[bidx, :T, :N] = prob
  
      return bb_prior
  
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 3 for calling the AlignmentModule obj's underlying member method code with example usage: obj._generate_prior(text_lengths, feats_lengths, w) and returns: bb_prior