class_docstr: Association without ground truth, from: Aka, O.; Burke, K.; Bäuerle, A.;
  Greer, C.; and Mitchell, M. 2021. Measuring model biases in the absence of ground
  truth. arXiv preprint arXiv:2103.03417.
  
  # Parameters
  
  num_classes : `int`
      Number of classes.
  num_protected_variable_labels : `int`
      Number of protected variable labels.
  association_metric : `str`, optional (default = `"npmixy"`).
      A generic association metric A(x, y), where x is an identity label and y is any other label.
      Examples include: nPMIxy (`"npmixy"`), nPMIy (`"npmiy"`), PMI^2 (`"pmisq"`), PMI (`"pmi"`)
      Empirically, nPMIxy and nPMIy are more capable of capturing labels across a range of
      marginal frequencies.
  gap_type : `str`, optional (default = `"ova"`).
      Either one-vs-all (`"ova"`) or pairwise (`"pairwise"`). One-vs-all gap is equivalent to
      A(x, y) - E[A(x', y)], where x' is in the set of all protected variable labels setminus {x}.
      Pairwise gaps are A(x, y) - A(x', y), for all x' in the set of all protected variable labels
      setminus {x}.
  
  !!! Note
      Assumes integer predictions, with each item to be classified
      having a single correct class.
class_docstr_tok: ["Association","without","ground","truth",",","from",":","Aka",",","O.",";","Burke",",","K.",";","B\u00e4uerle",",","A.",";","Greer",",","C.",";","and","Mitchell",",","M.","2021",".","Measuring","model","biases","in","the","absence","of","ground","truth",".","arXiv","preprint","arXiv:2103.03417",".","#","Parameters","num_classes",":","`","int","`","Number","of","classes",".","num_protected_variable_labels",":","`","int","`","Number","of","protected","variable","labels",".","association_metric",":","`","str","`",",","optional","(","default","=","`","``","npmixy","''","`",")",".","A","generic","association","metric","A","(","x",",","y",")",",","where","x","is","an","identity","label","and","y","is","any","other","label",".","Examples","include",":","nPMIxy","(","`","``","npmixy","''","`",")",",","nPMIy","(","`","``","npmiy","''","`",")",",","PMI^2","(","`","``","pmisq","''","`",")",",","PMI","(","`","``","pmi","''","`",")","Empirically",",","nPMIxy","and","nPMIy","are","more","capable","of","capturing","labels","across","a","range","of","marginal","frequencies",".","gap_type",":","`","str","`",",","optional","(","default","=","`","``","ova","''","`",")",".","Either","one-vs-all","(","`","``","ova","''","`",")","or","pairwise","(","`","``","pairwise","''","`",")",".","One-vs-all","gap","is","equivalent","to","A","(","x",",","y",")","-","E","[","A","(","x","'",",","y",")","]",",","where","x","'","is","in","the","set","of","all","protected","variable","labels","setminus","{","x","}",".","Pairwise","gaps","are","A","(","x",",","y",")","-","A","(","x","'",",","y",")",",","for","all","x","'","in","the","set","of","all","protected","variable","labels","setminus","{","x","}",".","!","!","!","Note","Assumes","integer","predictions",",","with","each","item","to","be","classified","having","a","single","correct","class","."]
code: def _all_pmi_terms(self) -> Dict[int, torch.Tensor]:
      if self._total_predictions == 0:
          return torch.full(
              (self._num_protected_variable_labels, self._num_classes),
              float("nan"),
          )
  
      device = self._y_counts.device
      prob_y = torch.zeros(self._num_classes).to(device)
      torch.div(self._y_counts, self._total_predictions, out=prob_y)
  
      joint = torch.zeros(
          (self._num_protected_variable_labels, self._num_classes)
      ).to(device)
      torch.div(
          self._joint_counts_by_protected_variable_label,
          self._total_predictions,
          out=joint,
      )
      if self.association_metric == "pmisq":
          torch.square_(joint)
  
      pmi_terms = torch.log(
          torch.div(
              joint,
              (
                  self._protected_variable_label_counts
                  / self._total_predictions
              ).unsqueeze(-1)
              * prob_y,
          )
      )
      if self.association_metric == "npmixy":
          pmi_terms.div_(torch.log(joint))
      elif self.association_metric == "npmiy":
          pmi_terms.div_(torch.log(prob_y))
  
      return pmi_terms
  
imports: from typing import Optional, Dict, Union, List
  import torch
  import torch.distributed
  from allennlp.common.util import is_distributed
  from allennlp.common.checks import ConfigurationError
  from allennlp.nn.util import dist_reduce_sum
  from allennlp.training.metrics.metric import Metric
label_desc: Use image node_id 7 for calling the AssociationWithoutGroundTruth obj's underlying member method code with example usage: obj._all_pmi_terms() and returns: pmi_terms, torch