class_docstr: Negative KL between the uniform and predicted distribution.
      Defined as:
          - KL(U || P(Y|X)) = - sum_i U_i * log (P(Y_i | X) / U_i)
                            = - sum_i U_i * log P(Y_i|X) + H[U]
                            = - (1/n) * sum_i log P(Y_i | X) + H[U]
  
  H[U] does not depend on X, thus it is omitted during optimization.
class_docstr_tok: ["Negative","KL","between","the","uniform","and","predicted","distribution",".","Defined","as",":","-","KL","(","U","||","P","(","Y|X",")",")","=","-","sum_i","U_i","*","log","(","P","(","Y_i","|","X",")","\/","U_i",")","=","-","sum_i","U_i","*","log","P","(","Y_i|X",")","+","H","[","U","]","=","-","(","1\/n",")","*","sum_i","log","P","(","Y_i","|","X",")","+","H","[","U","]","H","[","U","]","does","not","depend","on","X",",","thus","it","is","omitted","during","optimization","."]
code: def __call__(self, logits, targets, reduce=True):
      mask = targets.ne(self.ignore_index)
  
      loss = -logits.mean(dim=1)
  
      if reduce:
          return (
              loss[mask].mean()
              if mask.any()
              else torch.tensor(0.0, device=logits.device)
          )
  
      return loss
  
file_path: pytext/pytext/loss/regularizer.py
imports: import torch
  import torch.nn
  import torch.nn.functional
  from pytext.config import ConfigBase
  from .loss import Loss
label_desc: Use image node_id 1 for calling the UniformRegularizer obj's underlying member method code with example usage: obj.__call__(logits, targets, reduce) and returns: loss, unknown