code: def build_class_priors(
      labels,
      class_priors=None,
      weights=None,
      positive_pseudocount=1.0,
      negative_pseudocount=1.0,
  ):
      """build class priors, if necessary.
      For each class, the class priors are estimated as
      (P + sum_i w_i y_i) / (P + N + sum_i w_i),
      where y_i is the ith label, w_i is the ith weight, P is a pseudo-count of
      positive labels, and N is a pseudo-count of negative labels.
  
      Args:
          labels: A `Tensor` with shape [batch_size, num_classes].
              Entries should be in [0, 1].
          class_priors: None, or a floating point `Tensor` of shape [C]
              containing the prior probability of each class (i.e. the fraction of the
              training data consisting of positive examples). If None, the class
              priors are computed from `targets` with a moving average.
          weights: `Tensor` of shape broadcastable to labels, [N, 1] or [N, C],
              where `N = batch_size`, C = num_classes`
          positive_pseudocount: Number of positive labels used to initialize the class
              priors.
          negative_pseudocount: Number of negative labels used to initialize the class
              priors.
      Returns:
          class_priors: A Tensor of shape [num_classes] consisting of the
            weighted class priors, after updating with moving average ops if created.
      """
      if class_priors is not None:
          return class_priors
  
      N, C = labels.size()
  
      weighted_label_counts = (weights * labels).sum(0)
  
      weight_sum = weights.sum(0)
  
      class_priors = torch.div(
          weighted_label_counts + positive_pseudocount,
          weight_sum + positive_pseudocount + negative_pseudocount,
      )
  
      return class_priors
  
file_path: pytext/pytext/utils/loss.py
imports: import numpy
  import torch
  from .cuda import FloatTensor
label_desc: Use image node_id 2 for calling a global function with example usage: build_class_priors(labels, class_priors, weights, positive_pseudocount, negative_pseudocount) and returns: class_priors, class_priors