class_docstr: Just checks batch-equality of two tensors and computes an accuracy metric based on that.  This
  is similar to :class:`CategoricalAccuracy`, if you've already done a ``.max()`` on your
  predictions.  If you have categorical output, though, you should typically just use
  :class:`CategoricalAccuracy`.  The reason you might want to use this instead is if you've done
  some kind of constrained inference and don't have a prediction tensor that matches the API of
  :class:`CategoricalAccuracy`, which assumes a final dimension of size ``num_classes``.
docstr: Parameters
  ----------
  predictions : ``torch.Tensor``, required.
      A tensor of predictions of shape (batch_size, ...).
  gold_labels : ``torch.Tensor``, required.
      A tensor of the same shape as ``predictions``.
  mask: ``torch.Tensor``, optional (default = None).
      A tensor of the same shape as ``predictions``.
docstr_tok: ["Parameters","--","--","--","--","--","predictions",":","``","torch.Tensor","``",",","required",".","A","tensor","of","predictions","of","shape","(","batch_size",",","...",")",".","gold_labels",":","``","torch.Tensor","``",",","required",".","A","tensor","of","the","same","shape","as","``","predictions","``",".","mask",":","``","torch.Tensor","``",",","optional","(","default","=","None",")",".","A","tensor","of","the","same","shape","as","``","predictions","``","."]
code: def __call__(self, predictions, gold_labels, mask=None):
      """
      Parameters
      ----------
      predictions : ``torch.Tensor``, required.
          A tensor of predictions of shape (batch_size, ...).
      gold_labels : ``torch.Tensor``, required.
          A tensor of the same shape as ``predictions``.
      mask: ``torch.Tensor``, optional (default = None).
          A tensor of the same shape as ``predictions``.
      """
      predictions, gold_labels, mask = self.unwrap_to_tensors(
          predictions, gold_labels, mask
      )
  
      if mask is not None:
          # We can multiply by the mask up front, because we're just checking equality below, and
          # this way everything that's masked will be equal.
          predictions = predictions * mask
          gold_labels = gold_labels * mask
  
      batch_size = predictions.size(0)
      predictions = predictions.view(batch_size, -1)
      gold_labels = gold_labels.view(batch_size, -1)
  
      # The .prod() here is functioning as a logical and.
      correct = predictions.eq(gold_labels).prod(dim=1).float()
      count = torch.ones(gold_labels.size(0))
      self._correct_count += correct.sum()
      self._total_count += count.sum()
  
file_path: magnitude/pymagnitude/third_party/allennlp/training/metrics/boolean_accuracy.py
imports: from __future__ import division
  from __future__ import absolute_import
  import torch
  from allennlp.training.metrics.metric import Metric
label_desc: Use image node_id 2 for calling the BooleanAccuracy obj's underlying member method code with example usage: obj.__call__(predictions, gold_labels, mask) without return types