class_docstr: Sequence Top-K accuracy. 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,
  ):
      """
      # 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())
          )
  
      k = predictions.size()[1]
      expanded_size = list(gold_labels.size())
      expanded_size.insert(1, k)
      expanded_gold = gold_labels.unsqueeze(1).expand(expanded_size)
  
      if mask is not None:
          expanded_mask = mask.unsqueeze(1).expand(expanded_size)
          masked_gold = expanded_mask * expanded_gold
          masked_predictions = expanded_mask * predictions
      else:
          masked_gold = expanded_gold
          masked_predictions = predictions
  
      eqs = masked_gold.eq(masked_predictions)
      matches_per_question = eqs.min(dim=2)[0]
      some_match = matches_per_question.max(dim=1)[0]
      correct = some_match.sum().item()
  
      _total_count = predictions.size()[0]
      _correct_count = correct
  
      self.correct_count += dist_reduce_sum(_correct_count)
      self.total_count += dist_reduce_sum(_total_count)
  
file_path: allennlp/allennlp/training/metrics/sequence_accuracy.py
imports: from typing import Optional
  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 SequenceAccuracy obj's underlying member method code with example usage: obj.__call__(predictions, gold_labels, mask) without return types