class_docstr: Computes Precision, Recall and F1 with respect to a given ``positive_label``.
  For example, for a BIO tagging scheme, you would pass the classification index of
  the tag you are interested in, resulting in the Precision, Recall and F1 score being
  calculated for this tag only.
docstr: Parameters
  ----------
  predictions : ``torch.Tensor``, required.
      A tensor of predictions of shape (batch_size, ..., num_classes).
  gold_labels : ``torch.Tensor``, required.
      A tensor of integer class label of shape (batch_size, ...). It must be the same
      shape as the ``predictions`` tensor without the ``num_classes`` dimension.
  mask: ``torch.Tensor``, optional (default = None).
      A masking tensor the same size as ``gold_labels``.
docstr_tok: ["Parameters","--","--","--","--","--","predictions",":","``","torch.Tensor","``",",","required",".","A","tensor","of","predictions","of","shape","(","batch_size",",","...",",","num_classes",")",".","gold_labels",":","``","torch.Tensor","``",",","required",".","A","tensor","of","integer","class","label","of","shape","(","batch_size",",","...",")",".","It","must","be","the","same","shape","as","the","``","predictions","``","tensor","without","the","``","num_classes","``","dimension",".","mask",":","``","torch.Tensor","``",",","optional","(","default","=","None",")",".","A","masking","tensor","the","same","size","as","``","gold_labels","``","."]
code: def __call__(self, predictions, gold_labels, mask=None):
      """
      Parameters
      ----------
      predictions : ``torch.Tensor``, required.
          A tensor of predictions of shape (batch_size, ..., num_classes).
      gold_labels : ``torch.Tensor``, required.
          A tensor of integer class label of shape (batch_size, ...). It must be the same
          shape as the ``predictions`` tensor without the ``num_classes`` dimension.
      mask: ``torch.Tensor``, optional (default = None).
          A masking tensor the same size as ``gold_labels``.
      """
      predictions, gold_labels, mask = self.unwrap_to_tensors(
          predictions, gold_labels, mask
      )
  
      num_classes = predictions.size(-1)
      if (gold_labels >= num_classes).any():
          raise ConfigurationError(
              "A gold label passed to F1Measure contains an id >= {}, "
              "the number of classes.".format(num_classes)
          )
      if mask is None:
          mask = torch.ones_like(gold_labels)
      mask = mask.float()
      gold_labels = gold_labels.float()
      positive_label_mask = gold_labels.eq(self._positive_label).float()
      negative_label_mask = 1.0 - positive_label_mask
  
      argmax_predictions = predictions.max(-1)[1].float().squeeze(-1)
  
      # True Negatives: correct non-positive predictions.
      correct_null_predictions = (
          argmax_predictions != self._positive_label
      ).float() * negative_label_mask
      self._true_negatives += (
          correct_null_predictions.float() * mask
      ).sum()
  
      # True Positives: correct positively labeled predictions.
      correct_non_null_predictions = (
          argmax_predictions == self._positive_label
      ).float() * positive_label_mask
      self._true_positives += (
          correct_non_null_predictions * mask
      ).sum()
  
      # False Negatives: incorrect negatively labeled predictions.
      incorrect_null_predictions = (
          argmax_predictions != self._positive_label
      ).float() * positive_label_mask
      self._false_negatives += (incorrect_null_predictions * mask).sum()
  
      # False Positives: incorrect positively labeled predictions
      incorrect_non_null_predictions = (
          argmax_predictions == self._positive_label
      ).float() * negative_label_mask
      self._false_positives += (
          incorrect_non_null_predictions * mask
      ).sum()
  
file_path: magnitude/pymagnitude/third_party/allennlp/training/metrics/f1_measure.py
imports: from __future__ import division
  from __future__ import absolute_import
  import torch
  from allennlp.training.metrics.metric import Metric
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 2 for calling the F1Measure obj's underlying member method code with example usage: obj.__call__(predictions, gold_labels, mask) without return types