class_docstr: This ``Model`` implements the coreference resolution model described "End-to-end Neural
  Coreference Resolution"
  <https://www.semanticscholar.org/paper/End-to-end-Neural-Coreference-Resolution-Lee-He/3f2114893dc44eacac951f148fbff142ca200e83>
  by Lee et al., 2017.
  The basic outline of this model is to get an embedded representation of each span in the
  document. These span representations are scored and used to prune away spans that are unlikely
  to occur in a coreference cluster. For the remaining spans, the model decides which antecedent
  span (if any) they are coreferent with. The resulting coreference links, after applying
  transitivity, imply a clustering of the spans in the document.
  
  Parameters
  ----------
  vocab : ``Vocabulary``
  text_field_embedder : ``TextFieldEmbedder``
      Used to embed the ``text`` ``TextField`` we get as input to the model.
  context_layer : ``Seq2SeqEncoder``
      This layer incorporates contextual information for each word in the document.
  mention_feedforward : ``FeedForward``
      This feedforward network is applied to the span representations which is then scored
      by a linear layer.
  antecedent_feedforward: ``FeedForward``
      This feedforward network is applied to pairs of span representation, along with any
      pairwise features, which is then scored by a linear layer.
  feature_size: ``int``
      The embedding size for all the embedded features, such as distances or span widths.
  max_span_width: ``int``
      The maximum width of candidate spans.
  spans_per_word: float, required.
      A multiplier between zero and one which controls what percentage of candidate mention
      spans we retain with respect to the number of words in the document.
  max_antecedents: int, required.
      For each mention which survives the pruning stage, we consider this many antecedents.
  lexical_dropout: ``int``
      The probability of dropping out dimensions of the embedded text.
  initializer : ``InitializerApplicator``, optional (default=``InitializerApplicator()``)
      Used to initialize the model parameters.
  regularizer : ``RegularizerApplicator``, optional (default=``None``)
      If provided, will be used to calculate the regularization penalty during training.
docstr: Converts the list of spans and predicted antecedent indices into clusters
  of spans for each element in the batch.
  
  Parameters
  ----------
  output_dict : ``Dict[str, torch.Tensor]``, required.
      The result of calling :func:`forward` on an instance or batch of instances.
  
  Returns
  -------
  The same output dictionary, but with an additional ``clusters`` key:
  
  clusters : ``List[List[List[Tuple[int, int]]]]``
      A nested list, representing, for each instance in the batch, the list of clusters,
      which are in turn comprised of a list of (start, end) inclusive spans into the
      original document.
docstr_tok: ["Converts","the","list","of","spans","and","predicted","antecedent","indices","into","clusters","of","spans","for","each","element","in","the","batch",".","Parameters","--","--","--","--","--","output_dict",":","``","Dict","[","str",",","torch.Tensor","]","``",",","required",".","The","result","of","calling",":","func",":","`","forward","`","on","an","instance","or","batch","of","instances",".","Returns","--","--","--","-","The","same","output","dictionary",",","but","with","an","additional","``","clusters","``","key",":","clusters",":","``","List","[","List","[","List","[","Tuple","[","int",",","int","]","]","]","]","``","A","nested","list",",","representing",",","for","each","instance","in","the","batch",",","the","list","of","clusters",",","which","are","in","turn","comprised","of","a","list","of","(","start",",","end",")","inclusive","spans","into","the","original","document","."]
code: def decode(self, output_dict):
      """
      Converts the list of spans and predicted antecedent indices into clusters
      of spans for each element in the batch.
  
      Parameters
      ----------
      output_dict : ``Dict[str, torch.Tensor]``, required.
          The result of calling :func:`forward` on an instance or batch of instances.
  
      Returns
      -------
      The same output dictionary, but with an additional ``clusters`` key:
  
      clusters : ``List[List[List[Tuple[int, int]]]]``
          A nested list, representing, for each instance in the batch, the list of clusters,
          which are in turn comprised of a list of (start, end) inclusive spans into the
          original document.
      """
  
      # A tensor of shape (batch_size, num_spans_to_keep, 2), representing
      # the start and end indices of each span.
      batch_top_spans = output_dict["top_spans"].detach().cpu()
  
      # A tensor of shape (batch_size, num_spans_to_keep) representing, for each span,
      # the index into ``antecedent_indices`` which specifies the antecedent span. Additionally,
      # the index can be -1, specifying that the span has no predicted antecedent.
      batch_predicted_antecedents = (
          output_dict["predicted_antecedents"].detach().cpu()
      )
  
      # A tensor of shape (num_spans_to_keep, max_antecedents), representing the indices
      # of the predicted antecedents with respect to the 2nd dimension of ``batch_top_spans``
      # for each antecedent we considered.
      antecedent_indices = (
          output_dict["antecedent_indices"].detach().cpu()
      )
      batch_clusters = []
  
      # Calling zip() on two tensors results in an iterator over their
      # first dimension. This is iterating over instances in the batch.
      for top_spans, predicted_antecedents in izip(
          batch_top_spans, batch_predicted_antecedents
      ):
          spans_to_cluster_ids = {}
          clusters = []
  
          for i, (span, predicted_antecedent) in enumerate(
              izip(top_spans, predicted_antecedents)
          ):
              if predicted_antecedent < 0:
                  # We don't care about spans which are
                  # not co-referent with anything.
                  continue
  
              # Find the right cluster to update with this span.
              # To do this, we find the row in ``antecedent_indices``
              # corresponding to this span we are considering.
              # The predicted antecedent is then an index into this list
              # of indices, denoting the span from ``top_spans`` which is the
              # most likely antecedent.
              predicted_index = antecedent_indices[
                  i, predicted_antecedent
              ]
  
              antecedent_span = (
                  top_spans[predicted_index, 0].item(),
                  top_spans[predicted_index, 1].item(),
              )
  
              # Check if we've seen the span before.
              if antecedent_span in spans_to_cluster_ids:
                  predicted_cluster_id = spans_to_cluster_ids[
                      antecedent_span
                  ]
              else:
                  # We start a new cluster.
                  predicted_cluster_id = len(clusters)
                  # Append a new cluster containing only this span.
                  clusters.append([antecedent_span])
                  # Record the new id of this span.
                  spans_to_cluster_ids[
                      antecedent_span
                  ] = predicted_cluster_id
  
              # Now add the span we are currently considering.
              span_start, span_end = span[0].item(), span[1].item()
              clusters[predicted_cluster_id].append(
                  (span_start, span_end)
              )
              spans_to_cluster_ids[
                  (span_start, span_end)
              ] = predicted_cluster_id
          batch_clusters.append(clusters)
  
      output_dict["clusters"] = batch_clusters
      return output_dict
  
imports: from __future__ import absolute_import
  import logging
  import math
  import torch
  import torch.nn.functional
  from allennlp.data import Vocabulary
  from allennlp.models.model import Model
  from allennlp.modules.token_embedders import Embedding
  from allennlp.modules import FeedForward
  from allennlp.modules import Seq2SeqEncoder, TimeDistributed, TextFieldEmbedder, SpanPruner
  from allennlp.modules.span_extractors import SelfAttentiveSpanExtractor, EndpointSpanExtractor
  from allennlp.nn import util, InitializerApplicator, RegularizerApplicator
  from allennlp.training.metrics import MentionRecall, ConllCorefScores
label_desc: Use image node_id 3 for calling the CoreferenceResolver obj's underlying member method code with example usage: obj.decode(output_dict) and returns: output_dict