class_docstr: Unigram top-K recall. This does not take word order into account. Assumes
  integer labels, with each item to be classified having a single correct
  class.
class_docstr_tok: ["Unigram","top-K","recall",".","This","does","not","take","word","order","into","account",".","Assumes","integer","labels",",","with","each","item","to","be","classified","having","a","single","correct","class","."]
docstr: # Parameters
  
  predictions : `torch.Tensor`, required.
      A tensor of predictions of shape (batch_size, k, sequence_length).
  gold_labels : `torch.Tensor`, required.
      A tensor of integer class label of shape (batch_size, sequence_length).
  mask : `torch.BoolTensor`, 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",",","k",",","sequence_length",")",".","gold_labels",":","`","torch.Tensor","`",",","required",".","A","tensor","of","integer","class","label","of","shape","(","batch_size",",","sequence_length",")",".","mask",":","`","torch.BoolTensor","`",",","optional","(","default","=","`","None","`",")",".","A","masking","tensor","the","same","size","as","`","gold_labels","`","."]
code: def __call__(
      self,
      predictions: torch.Tensor,
      gold_labels: torch.Tensor,
      mask: Optional[torch.BoolTensor] = None,
      end_index: int = sys.maxsize,
  ):
      """
      # Parameters
  
      predictions : `torch.Tensor`, required.
          A tensor of predictions of shape (batch_size, k, sequence_length).
      gold_labels : `torch.Tensor`, required.
          A tensor of integer class label of shape (batch_size, sequence_length).
      mask : `torch.BoolTensor`, optional (default = `None`).
          A masking tensor the same size as `gold_labels`.
      """
      predictions, gold_labels, mask = self.detach_tensors(
          predictions, gold_labels, mask
      )
  
      # Some sanity checks.
      if gold_labels.dim() != predictions.dim() - 1:
          raise ConfigurationError(
              "gold_labels must have dimension == predictions.dim() - 1 but "
              "found tensor of shape: {}".format(gold_labels.size())
          )
      if mask is not None and mask.size() != gold_labels.size():
          raise ConfigurationError(
              "mask must have the same size as predictions but "
              "found tensor of shape: {}".format(mask.size())
          )
  
      batch_size = predictions.size()[0]
      correct = 0.0
      for i in range(batch_size):
          beams = predictions[i]
          cur_gold = gold_labels[i]
  
          if mask is not None:
              masked_gold = cur_gold * mask[i]
          else:
              masked_gold = cur_gold
          cleaned_gold = [
              x for x in masked_gold if x not in (0, end_index)
          ]
  
          retval = 0.0
          for word in cleaned_gold:
              stillsearch = True
              for beam in beams:
                  # word is from cleaned gold which doesn't have 0 or
                  # end_index, so we don't need to explicitly remove those
                  # from beam.
                  if stillsearch and word in beam:
                      retval += 1 / len(cleaned_gold)
                      stillsearch = False
          correct += retval
  
      _correct_count = correct
      _total_count = predictions.size()[0]
  
      self.correct_count += dist_reduce_sum(_correct_count)
      self.total_count += dist_reduce_sum(_total_count)
  
file_path: allennlp/allennlp/training/metrics/unigram_recall.py
imports: from typing import Optional
  import sys
  import torch
  from allennlp.common.checks import ConfigurationError
  from allennlp.training.metrics.metric import Metric
  from allennlp.nn.util import dist_reduce_sum
label_desc: Use image node_id 2 for calling the UnigramRecall obj's underlying member method code with example usage: obj.__call__(predictions, gold_labels, mask, end_index) without return types