class_docstr: Spectogram Denoiser.
  
  Ref: https://arxiv.org/pdf/2207.06389.pdf.
docstr: Calculate forward propagation.
  
  Args:
      xs (torch.Tensor): Phoneme-encoded tensor (#batch, time, dims)
      ys (Optional[torch.Tensor], optional): Mel-based reference
          tensor (#batch, time, mels). Defaults to None.
      masks (Optional[torch.Tensor], optional): Mask tensor (#batch, time).
          Defaults to None.
  
  Returns:
      torch.Tensor: Output tensor (#batch, time, dims).
docstr_tok: ["Calculate","forward","propagation",".","Args",":","xs","(","torch.Tensor",")",":","Phoneme-encoded","tensor","(","#","batch",",","time",",","dims",")","ys","(","Optional","[","torch.Tensor","]",",","optional",")",":","Mel-based","reference","tensor","(","#","batch",",","time",",","mels",")",".","Defaults","to","None",".","masks","(","Optional","[","torch.Tensor","]",",","optional",")",":","Mask","tensor","(","#","batch",",","time",")",".","Defaults","to","None",".","Returns",":","torch.Tensor",":","Output","tensor","(","#","batch",",","time",",","dims",")","."]
code: def forward(
      self,
      xs: torch.Tensor,
      ys: Optional[torch.Tensor] = None,
      masks: Optional[torch.Tensor] = None,
      is_inference: bool = False,
  ) -> torch.Tensor:
      """Calculate forward propagation.
  
      Args:
          xs (torch.Tensor): Phoneme-encoded tensor (#batch, time, dims)
          ys (Optional[torch.Tensor], optional): Mel-based reference
              tensor (#batch, time, mels). Defaults to None.
          masks (Optional[torch.Tensor], optional): Mask tensor (#batch, time).
              Defaults to None.
  
      Returns:
          torch.Tensor: Output tensor (#batch, time, dims).
  
      """
      if is_inference:
          return self.inference(xs)
  
      batch_size = xs.shape[0]
      timesteps = (
          torch.randint(0, self.timesteps + 1, (batch_size,))
          .to(xs.device)
          .long()
      )
  
      # Diffusion
      ys_noise = self.diffusion(ys, timesteps)  # (batch, 1, dims, time)
      ys_noise = ys_noise * masks.unsqueeze(1)
  
      # Denoise
      ys_denoise = self.forward_denoise(ys_noise, timesteps, xs)
      ys_denoise = ys_denoise * masks
      return ys_denoise.transpose(1, 2)
  
imports: import math
  from typing import Optional, Union
  import numpy
  import torch
  from torch import nn
  from torch.nn import functional
  from espnet.nets.pytorch_backend.transformer.embedding import PositionalEncoding
label_desc: Use image node_id 2 for calling the SpectogramDenoiser obj's underlying member method code with example usage: obj.forward(xs, ys, masks, is_inference) and returns: ys_denoise, self