docstr: Generate an attention mask from the linear scale durations.
  
  Args:
      dr (Tensor): Linear scale durations.
      x_mask (Tensor): Mask for the input (character) sequence.
      y_mask (Tensor): Mask for the output (spectrogram) sequence. Compute it from the predicted durations
          if None. Defaults to None.
  
  Shapes
     - dr: :math:`(B, T_{en})`
     - x_mask: :math:`(B, T_{en})`
     - y_mask: :math:`(B, T_{de})`
docstr_tok: ["Generate","an","attention","mask","from","the","linear","scale","durations",".","Args",":","dr","(","Tensor",")",":","Linear","scale","durations",".","x_mask","(","Tensor",")",":","Mask","for","the","input","(","character",")","sequence",".","y_mask","(","Tensor",")",":","Mask","for","the","output","(","spectrogram",")","sequence",".","Compute","it","from","the","predicted","durations","if","None",".","Defaults","to","None",".","Shapes","-","dr",":",":","math",":","`","(","B",",","T_","{","en","}",")","`","-","x_mask",":",":","math",":","`","(","B",",","T_","{","en","}",")","`","-","y_mask",":",":","math",":","`","(","B",",","T_","{","de","}",")","`"]
code: def generate_attn(dr, x_mask, y_mask=None):
      """Generate an attention mask from the linear scale durations.
  
      Args:
          dr (Tensor): Linear scale durations.
          x_mask (Tensor): Mask for the input (character) sequence.
          y_mask (Tensor): Mask for the output (spectrogram) sequence. Compute it from the predicted durations
              if None. Defaults to None.
  
      Shapes
         - dr: :math:`(B, T_{en})`
         - x_mask: :math:`(B, T_{en})`
         - y_mask: :math:`(B, T_{de})`
      """
      # compute decode mask from the durations
      if y_mask is None:
          y_lengths = dr.sum(1).long()
          y_lengths[y_lengths < 1] = 1
          y_mask = torch.unsqueeze(
              sequence_mask(y_lengths, None), 1
          ).to(dr.dtype)
      attn_mask = torch.unsqueeze(x_mask, -1) * torch.unsqueeze(
          y_mask, 2
      )
      attn = generate_path(dr, attn_mask.squeeze(1)).to(dr.dtype)
      return attn
  
imports: from typing import Callable, Dict, Tuple
  import torch
  import torch.nn.functional
  from coqpit import Coqpit
  from torch import nn
  from TTS.tts.layers.delightful_tts.conformer import Conformer
  from TTS.tts.layers.delightful_tts.encoders import PhonemeLevelProsodyEncoder, UtteranceLevelProsodyEncoder, get_mask_from_lengths
  from TTS.tts.layers.delightful_tts.energy_adaptor import EnergyAdaptor
  from TTS.tts.layers.delightful_tts.networks import EmbeddingPadded, positional_encoding
  from TTS.tts.layers.delightful_tts.phoneme_prosody_predictor import PhonemeProsodyPredictor
  from TTS.tts.layers.delightful_tts.pitch_adaptor import PitchAdaptor
  from TTS.tts.layers.delightful_tts.variance_predictor import VariancePredictor
  from TTS.tts.layers.generic.aligner import AlignmentNetwork
  from TTS.tts.utils.helpers import generate_path, maximum_path, sequence_mask
label_desc: Use image node_id 8 for calling the AcousticModel obj's underlying member method code with example usage: obj.generate_attn(dr, x_mask, y_mask) and returns: attn