class_docstr: The Conll SRL metrics are based on exact span matching. This metric
  implements span-based precision and recall metrics for a BIO tagging
  scheme. It will produce precision, recall and F1 measures per tag, as
  well as overall statistics. Note that the implementation of this metric
  is not exactly the same as the perl script used to evaluate the CONLL 2005
  data - particularly, it does not consider continuations or reference spans
  as constituents of the original span. However, it is a close proxy, which
  can be helpful for judging model performance during training. This metric
  works properly when the spans are unlabeled (i.e., your labels are
  simply "B", "I", "O" if using the "BIO" label encoding).
class_docstr_tok: ["The","Conll","SRL","metrics","are","based","on","exact","span","matching",".","This","metric","implements","span-based","precision","and","recall","metrics","for","a","BIO","tagging","scheme",".","It","will","produce","precision",",","recall","and","F1","measures","per","tag",",","as","well","as","overall","statistics",".","Note","that","the","implementation","of","this","metric","is","not","exactly","the","same","as","the","perl","script","used","to","evaluate","the","CONLL","2005","data","-","particularly",",","it","does","not","consider","continuations","or","reference","spans","as","constituents","of","the","original","span",".","However",",","it","is","a","close","proxy",",","which","can","be","helpful","for","judging","model","performance","during","training",".","This","metric","works","properly","when","the","spans","are","unlabeled","(","i.e.",",","your","labels","are","simply","``","B","''",",","``","I","''",",","``","O","''","if","using","the","``","BIO","''","label","encoding",")","."]
docstr: # Parameters
  
  predictions : `torch.Tensor`, required.
      A tensor of predictions of shape (batch_size, sequence_length, num_classes).
  gold_labels : `torch.Tensor`, required.
      A tensor of integer class label of shape (batch_size, sequence_length). It must be the same
      shape as the `predictions` tensor without the `num_classes` dimension.
  mask : `torch.BoolTensor`, optional (default = `None`).
      A masking tensor the same size as `gold_labels`.
  prediction_map : `torch.Tensor`, optional (default = `None`).
      A tensor of size (batch_size, num_classes) which provides a mapping from the index of predictions
      to the indices of the label vocabulary. If provided, the output label at each timestep will be
      `vocabulary.get_index_to_token_vocabulary(prediction_map[batch, argmax(predictions[batch, t]))`,
      rather than simply `vocabulary.get_index_to_token_vocabulary(argmax(predictions[batch, t]))`.
      This is useful in cases where each Instance in the dataset is associated with a different possible
      subset of labels from a large label-space (IE FrameNet, where each frame has a different set of
      possible roles associated with it).
docstr_tok: ["#","Parameters","predictions",":","`","torch.Tensor","`",",","required",".","A","tensor","of","predictions","of","shape","(","batch_size",",","sequence_length",",","num_classes",")",".","gold_labels",":","`","torch.Tensor","`",",","required",".","A","tensor","of","integer","class","label","of","shape","(","batch_size",",","sequence_length",")",".","It","must","be","the","same","shape","as","the","`","predictions","`","tensor","without","the","`","num_classes","`","dimension",".","mask",":","`","torch.BoolTensor","`",",","optional","(","default","=","`","None","`",")",".","A","masking","tensor","the","same","size","as","`","gold_labels","`",".","prediction_map",":","`","torch.Tensor","`",",","optional","(","default","=","`","None","`",")",".","A","tensor","of","size","(","batch_size",",","num_classes",")","which","provides","a","mapping","from","the","index","of","predictions","to","the","indices","of","the","label","vocabulary",".","If","provided",",","the","output","label","at","each","timestep","will","be","`","vocabulary.get_index_to_token_vocabulary","(","prediction_map","[","batch",",","argmax","(","predictions","[","batch",",","t","]",")",")","`",",","rather","than","simply","`","vocabulary.get_index_to_token_vocabulary","(","argmax","(","predictions","[","batch",",","t","]",")",")","`",".","This","is","useful","in","cases","where","each","Instance","in","the","dataset","is","associated","with","a","different","possible","subset","of","labels","from","a","large","label-space","(","IE","FrameNet",",","where","each","frame","has","a","different","set","of","possible","roles","associated","with","it",")","."]
code: def __call__(
      self,
      predictions: torch.Tensor,
      gold_labels: torch.Tensor,
      mask: Optional[torch.BoolTensor] = None,
      prediction_map: Optional[torch.Tensor] = None,
  ):
      """
      # Parameters
  
      predictions : `torch.Tensor`, required.
          A tensor of predictions of shape (batch_size, sequence_length, num_classes).
      gold_labels : `torch.Tensor`, required.
          A tensor of integer class label of shape (batch_size, sequence_length). It must be the same
          shape as the `predictions` tensor without the `num_classes` dimension.
      mask : `torch.BoolTensor`, optional (default = `None`).
          A masking tensor the same size as `gold_labels`.
      prediction_map : `torch.Tensor`, optional (default = `None`).
          A tensor of size (batch_size, num_classes) which provides a mapping from the index of predictions
          to the indices of the label vocabulary. If provided, the output label at each timestep will be
          `vocabulary.get_index_to_token_vocabulary(prediction_map[batch, argmax(predictions[batch, t]))`,
          rather than simply `vocabulary.get_index_to_token_vocabulary(argmax(predictions[batch, t]))`.
          This is useful in cases where each Instance in the dataset is associated with a different possible
          subset of labels from a large label-space (IE FrameNet, where each frame has a different set of
          possible roles associated with it).
      """
      if mask is None:
          mask = torch.ones_like(gold_labels).bool()
  
      (
          predictions,
          gold_labels,
          mask,
          prediction_map,
      ) = self.detach_tensors(
          predictions, gold_labels, mask, prediction_map
      )
  
      num_classes = predictions.size(-1)
      if (gold_labels >= num_classes).any():
          raise ConfigurationError(
              "A gold label passed to SpanBasedF1Measure contains an "
              "id >= {}, the number of classes.".format(num_classes)
          )
  
      sequence_lengths = get_lengths_from_binary_sequence_mask(mask)
      argmax_predictions = predictions.max(-1)[1]
  
      if prediction_map is not None:
          argmax_predictions = torch.gather(
              prediction_map, 1, argmax_predictions
          )
          gold_labels = torch.gather(
              prediction_map, 1, gold_labels.long()
          )
  
      argmax_predictions = argmax_predictions.float()
  
      # Iterate over timesteps in batch.
      batch_size = gold_labels.size(0)
      for i in range(batch_size):
          sequence_prediction = argmax_predictions[i, :]
          sequence_gold_label = gold_labels[i, :]
          length = sequence_lengths[i]
  
          if length == 0:
              # It is possible to call this metric with sequences which are
              # completely padded. These contribute nothing, so we skip these rows.
              continue
  
          predicted_string_labels = [
              self._label_vocabulary[label_id]
              for label_id in sequence_prediction[:length].tolist()
          ]
          gold_string_labels = [
              self._label_vocabulary[label_id]
              for label_id in sequence_gold_label[:length].tolist()
          ]
  
          tags_to_spans_function: TAGS_TO_SPANS_FUNCTION_TYPE
          # `label_encoding` is empty and `tags_to_spans_function` is provided.
          if (
              self._label_encoding is None
              and self._tags_to_spans_function
          ):
              tags_to_spans_function = self._tags_to_spans_function
          # Search by `label_encoding`.
          elif self._label_encoding == "BIO":
              tags_to_spans_function = bio_tags_to_spans
          elif self._label_encoding == "IOB1":
              tags_to_spans_function = iob1_tags_to_spans
          elif self._label_encoding == "BIOUL":
              tags_to_spans_function = bioul_tags_to_spans
          elif self._label_encoding == "BMES":
              tags_to_spans_function = bmes_tags_to_spans
          else:
              raise ValueError(
                  f"Unexpected label encoding scheme '{self._label_encoding}'"
              )
  
          predicted_spans = tags_to_spans_function(
              predicted_string_labels, self._ignore_classes
          )
          gold_spans = tags_to_spans_function(
              gold_string_labels, self._ignore_classes
          )
  
          predicted_spans = self._handle_continued_spans(
              predicted_spans
          )
          gold_spans = self._handle_continued_spans(gold_spans)
  
          for span in predicted_spans:
              if span in gold_spans:
                  self._true_positives[span[0]] += 1
                  gold_spans.remove(span)
              else:
                  self._false_positives[span[0]] += 1
          # These spans weren't predicted.
          for span in gold_spans:
              self._false_negatives[span[0]] += 1
  
file_path: allennlp/allennlp/training/metrics/span_based_f1_measure.py
imports: from typing import Dict, List, Optional, Set, Callable
  from collections import defaultdict
  import torch
  from allennlp.common.util import is_distributed
  from allennlp.common.checks import ConfigurationError
  from allennlp.nn.util import get_lengths_from_binary_sequence_mask
  from allennlp.data.vocabulary import Vocabulary
  from allennlp.training.metrics.metric import Metric
  from allennlp.data.dataset_readers.dataset_utils.span_utils import bio_tags_to_spans, bioul_tags_to_spans, iob1_tags_to_spans, bmes_tags_to_spans, TypedStringSpan
label_desc: Use image node_id 2 for calling the SpanBasedF1Measure obj's underlying member method code with example usage: obj.__call__(predictions, gold_labels, mask, prediction_map) without return types