class_docstr: This ``SpanConstituencyParser`` simply encodes a sequence of text
  with a stacked ``Seq2SeqEncoder``, extracts span representations using a
  ``SpanExtractor``, and then predicts a label for each span in the sequence.
  These labels are non-terminal nodes in a constituency parse tree, which we then
  greedily reconstruct.
  
  Parameters
  ----------
  vocab : ``Vocabulary``, required
      A Vocabulary, required in order to compute sizes for input/output projections.
  text_field_embedder : ``TextFieldEmbedder``, required
      Used to embed the ``tokens`` ``TextField`` we get as input to the model.
  span_extractor : ``SpanExtractor``, required.
      The method used to extract the spans from the encoded sequence.
  encoder : ``Seq2SeqEncoder``, required.
      The encoder that we will use in between embedding tokens and
      generating span representations.
  feedforward : ``FeedForward``, required.
      The FeedForward layer that we will use in between the encoder and the linear
      projection to a distribution over span labels.
  pos_tag_embedding : ``Embedding``, optional.
      Used to embed the ``pos_tags`` ``SequenceLabelField`` we get as input to the model.
  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.
  evalb_directory_path : ``str``, optional (default=``DEFAULT_EVALB_DIR``)
      The path to the directory containing the EVALB executable used to score
      bracketed parses. By default, will use the EVALB included with allennlp,
      which is located at allennlp/tools/EVALB . If ``None``, EVALB scoring
      is not used.
class_docstr_tok: ["This","``","SpanConstituencyParser","``","simply","encodes","a","sequence","of","text","with","a","stacked","``","Seq2SeqEncoder","``",",","extracts","span","representations","using","a","``","SpanExtractor","``",",","and","then","predicts","a","label","for","each","span","in","the","sequence",".","These","labels","are","non-terminal","nodes","in","a","constituency","parse","tree",",","which","we","then","greedily","reconstruct",".","Parameters","--","--","--","--","--","vocab",":","``","Vocabulary","``",",","required","A","Vocabulary",",","required","in","order","to","compute","sizes","for","input\/output","projections",".","text_field_embedder",":","``","TextFieldEmbedder","``",",","required","Used","to","embed","the","``","tokens","``","``","TextField","``","we","get","as","input","to","the","model",".","span_extractor",":","``","SpanExtractor","``",",","required",".","The","method","used","to","extract","the","spans","from","the","encoded","sequence",".","encoder",":","``","Seq2SeqEncoder","``",",","required",".","The","encoder","that","we","will","use","in","between","embedding","tokens","and","generating","span","representations",".","feedforward",":","``","FeedForward","``",",","required",".","The","FeedForward","layer","that","we","will","use","in","between","the","encoder","and","the","linear","projection","to","a","distribution","over","span","labels",".","pos_tag_embedding",":","``","Embedding","``",",","optional",".","Used","to","embed","the","``","pos_tags","``","``","SequenceLabelField","``","we","get","as","input","to","the","model",".","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",".","evalb_directory_path",":","``","str","``",",","optional","(","default=","``","DEFAULT_EVALB_DIR","``",")","The","path","to","the","directory","containing","the","EVALB","executable","used","to","score","bracketed","parses",".","By","default",",","will","use","the","EVALB","included","with","allennlp",",","which","is","located","at","allennlp\/tools\/EVALB",".","If","``","None","``",",","EVALB","scoring","is","not","used","."]
docstr: Given a set of spans, removes spans which overlap by evaluating the difference
  in probability between one being labeled and the other explicitly having no label
  and vice-versa. The worst case time complexity of this method is ``O(k * n^4)`` where ``n``
  is the length of the sentence that the spans were enumerated from (and therefore
  ``k * m^2`` complexity with respect to the number of spans ``m``) and ``k`` is the
  number of conflicts. However, in practice, there are very few conflicts. Hopefully.
  
  This function modifies ``spans`` to remove overlapping spans.
  
  Parameters
  ----------
  spans: ``List[SpanInformation]``, required.
      A list of spans, where each span is a ``namedtuple`` containing the
      following attributes:
  
  start : ``int``
      The start index of the span.
  end : ``int``
      The exclusive end index of the span.
  no_label_prob : ``float``
      The probability of this span being assigned the ``NO-LABEL`` label.
  label_prob : ``float``
      The probability of the most likely label.
  
  Returns
  -------
  A modified list of ``spans``, with the conflicts resolved by considering local
  differences between pairs of spans and removing one of the two spans.
docstr_tok: ["Given","a","set","of","spans",",","removes","spans","which","overlap","by","evaluating","the","difference","in","probability","between","one","being","labeled","and","the","other","explicitly","having","no","label","and","vice-versa",".","The","worst","case","time","complexity","of","this","method","is","``","O","(","k","*","n^4",")","``","where","``","n","``","is","the","length","of","the","sentence","that","the","spans","were","enumerated","from","(","and","therefore","``","k","*","m^2","``","complexity","with","respect","to","the","number","of","spans","``","m","``",")","and","``","k","``","is","the","number","of","conflicts",".","However",",","in","practice",",","there","are","very","few","conflicts",".","Hopefully",".","This","function","modifies","``","spans","``","to","remove","overlapping","spans",".","Parameters","--","--","--","--","--","spans",":","``","List","[","SpanInformation","]","``",",","required",".","A","list","of","spans",",","where","each","span","is","a","``","namedtuple","``","containing","the","following","attributes",":","start",":","``","int","``","The","start","index","of","the","span",".","end",":","``","int","``","The","exclusive","end","index","of","the","span",".","no_label_prob",":","``","float","``","The","probability","of","this","span","being","assigned","the","``","NO-LABEL","``","label",".","label_prob",":","``","float","``","The","probability","of","the","most","likely","label",".","Returns","--","--","--","-","A","modified","list","of","``","spans","``",",","with","the","conflicts","resolved","by","considering","local","differences","between","pairs","of","spans","and","removing","one","of","the","two","spans","."]
code: def resolve_overlap_conflicts_greedily(spans):
      """
      Given a set of spans, removes spans which overlap by evaluating the difference
      in probability between one being labeled and the other explicitly having no label
      and vice-versa. The worst case time complexity of this method is ``O(k * n^4)`` where ``n``
      is the length of the sentence that the spans were enumerated from (and therefore
      ``k * m^2`` complexity with respect to the number of spans ``m``) and ``k`` is the
      number of conflicts. However, in practice, there are very few conflicts. Hopefully.
  
      This function modifies ``spans`` to remove overlapping spans.
  
      Parameters
      ----------
      spans: ``List[SpanInformation]``, required.
          A list of spans, where each span is a ``namedtuple`` containing the
          following attributes:
  
      start : ``int``
          The start index of the span.
      end : ``int``
          The exclusive end index of the span.
      no_label_prob : ``float``
          The probability of this span being assigned the ``NO-LABEL`` label.
      label_prob : ``float``
          The probability of the most likely label.
  
      Returns
      -------
      A modified list of ``spans``, with the conflicts resolved by considering local
      differences between pairs of spans and removing one of the two spans.
      """
      conflicts_exist = True
      while conflicts_exist:
          conflicts_exist = False
          for span1_index, span1 in enumerate(spans):
              for span2_index, span2 in list(enumerate(spans))[
                  span1_index + 1 :
              ]:
                  if (
                      span1.start < span2.start < span1.end < span2.end
                      or span2.start
                      < span1.start
                      < span2.end
                      < span1.end
                  ):
                      # The spans overlap.
                      conflicts_exist = True
                      # What's the more likely situation: that span2 was labeled
                      # and span1 was unlabled, or that span1 was labeled and span2
                      # was unlabled? In the first case, we delete span2 from the
                      # set of spans to form the tree - in the second case, we delete
                      # span1.
                      if (
                          span1.no_label_prob + span2.label_prob
                          < span2.no_label_prob + span1.label_prob
                      ):
                          spans.pop(span2_index)
                      else:
                          spans.pop(span1_index)
                      break
      return spans
  
imports: from __future__ import absolute_import
  import torch
  from torch.nn.modules.linear import Linear
  from nltk import Tree
  from allennlp.common.checks import check_dimensions_match
  from allennlp.data import Vocabulary
  from allennlp.modules import Seq2SeqEncoder, TimeDistributed, TextFieldEmbedder, FeedForward
  from allennlp.modules.token_embedders import Embedding
  from allennlp.modules.span_extractors.span_extractor import SpanExtractor
  from allennlp.models.model import Model
  from allennlp.nn import InitializerApplicator, RegularizerApplicator
  from allennlp.nn.util import get_text_field_mask, sequence_cross_entropy_with_logits
  from allennlp.nn.util import last_dim_softmax, get_lengths_from_binary_sequence_mask
  from allennlp.training.metrics import CategoricalAccuracy
  from allennlp.training.metrics import EvalbBracketingScorer, DEFAULT_EVALB_DIR
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 5 for calling the SpanConstituencyParser obj's underlying member method code with example usage: obj.resolve_overlap_conflicts_greedily(spans) and returns: spans