class_docstr: Base implementation for KL Divergence metric.
  
  The KL divergence is measured between probability distributions
  of class predictions returned by a pre-trained audio classification model.
  When the KL-divergence is low, the generated audio is expected to
  have similar acoustic characteristics as the reference audio,
  according to the classifier.
class_docstr_tok: ["Base","implementation","for","KL","Divergence","metric",".","The","KL","divergence","is","measured","between","probability","distributions","of","class","predictions","returned","by","a","pre-trained","audio","classification","model",".","When","the","KL-divergence","is","low",",","the","generated","audio","is","expected","to","have","similar","acoustic","characteristics","as","the","reference","audio",",","according","to","the","classifier","."]
docstr: Calculates running KL-Divergence loss between batches of audio
  preds (generated) and target (ground-truth)
  Args:
      preds (torch.Tensor): Audio samples to evaluate, of shape [B, C, T].
      targets (torch.Tensor): Target samples to compare against, of shape [B, C, T].
      sizes (torch.Tensor): Actual audio sample length, of shape [B].
      sample_rates (torch.Tensor): Actual audio sample rate, of shape [B].
docstr_tok: ["Calculates","running","KL-Divergence","loss","between","batches","of","audio","preds","(","generated",")","and","target","(","ground-truth",")","Args",":","preds","(","torch.Tensor",")",":","Audio","samples","to","evaluate",",","of","shape","[","B",",","C",",","T","]",".","targets","(","torch.Tensor",")",":","Target","samples","to","compare","against",",","of","shape","[","B",",","C",",","T","]",".","sizes","(","torch.Tensor",")",":","Actual","audio","sample","length",",","of","shape","[","B","]",".","sample_rates","(","torch.Tensor",")",":","Actual","audio","sample","rate",",","of","shape","[","B","]","."]
code: def update(
      self,
      preds: torch.Tensor,
      targets: torch.Tensor,
      sizes: torch.Tensor,
      sample_rates: torch.Tensor,
  ) -> None:
      """Calculates running KL-Divergence loss between batches of audio
      preds (generated) and target (ground-truth)
      Args:
          preds (torch.Tensor): Audio samples to evaluate, of shape [B, C, T].
          targets (torch.Tensor): Target samples to compare against, of shape [B, C, T].
          sizes (torch.Tensor): Actual audio sample length, of shape [B].
          sample_rates (torch.Tensor): Actual audio sample rate, of shape [B].
      """
      assert preds.shape == targets.shape
      assert (
          preds.size(0) > 0
      ), "Cannot update the loss with empty tensors"
      preds_probs = self._get_label_distribution(
          preds, sizes, sample_rates
      )
      targets_probs = self._get_label_distribution(
          targets, sizes, sample_rates
      )
      if preds_probs is not None and targets_probs is not None:
          assert preds_probs.shape == targets_probs.shape
          kld_scores = kl_divergence(preds_probs, targets_probs)
          assert not torch.isnan(
              kld_scores
          ).any(), "kld_scores contains NaN value(s)!"
          self.kld_pq_sum += torch.sum(kld_scores)
          kld_qp_scores = kl_divergence(targets_probs, preds_probs)
          self.kld_qp_sum += torch.sum(kld_qp_scores)
          self.weight += torch.tensor(kld_scores.size(0))
  
imports: import contextlib
  from functools import partial
  import logging
  import os
  import typing
  import torch
  import torchmetrics
  from ..data.audio_utils import convert_audio
label_desc: Use image node_id 3 for calling the KLDivergenceMetric obj's underlying member method code with example usage: obj.update(preds, targets, sizes, sample_rates) without return types