class_docstr: Reads a single CoNLL-formatted file. This is the same file format as used in the
  :class:`~allennlp.data.dataset_readers.semantic_role_labelling.SrlReader`, but is preprocessed
  to dump all documents into a single file per train, dev and test split. See
  scripts/compile_coref_data.sh for more details of how to pre-process the Ontonotes 5.0 data
  into the correct format.
  
  Returns a ``Dataset`` where the ``Instances`` have four fields: ``text``, a ``TextField``
  containing the full document text, ``spans``, a ``ListField[SpanField]`` of inclusive start and
  end indices for span candidates, and ``metadata``, a ``MetadataField`` that stores the instance's
  original text. For data with gold cluster labels, we also include the original ``clusters``
  (a list of list of index pairs) and a ``SequenceLabelField`` of cluster ids for every span
  candidate.
  
  Parameters
  ----------
  max_span_width: ``int``, required.
      The maximum width of candidate spans to consider.
  token_indexers : ``Dict[str, TokenIndexer]``, optional
      This is used to index the words in the document.  See :class:`TokenIndexer`.
      Default is ``{"tokens": SingleIdTokenIndexer()}``.
class_docstr_tok: ["Reads","a","single","CoNLL-formatted","file",".","This","is","the","same","file","format","as","used","in","the",":","class",":","`","~allennlp.data.dataset_readers.semantic_role_labelling.SrlReader","`",",","but","is","preprocessed","to","dump","all","documents","into","a","single","file","per","train",",","dev","and","test","split",".","See","scripts\/compile_coref_data.sh","for","more","details","of","how","to","pre-process","the","Ontonotes","5.0","data","into","the","correct","format",".","Returns","a","``","Dataset","``","where","the","``","Instances","``","have","four","fields",":","``","text","``",",","a","``","TextField","``","containing","the","full","document","text",",","``","spans","``",",","a","``","ListField","[","SpanField","]","``","of","inclusive","start","and","end","indices","for","span","candidates",",","and","``","metadata","``",",","a","``","MetadataField","``","that","stores","the","instance's","original","text",".","For","data","with","gold","cluster","labels",",","we","also","include","the","original","``","clusters","``","(","a","list","of","list","of","index","pairs",")","and","a","``","SequenceLabelField","``","of","cluster","ids","for","every","span","candidate",".","Parameters","--","--","--","--","--","max_span_width",":","``","int","``",",","required",".","The","maximum","width","of","candidate","spans","to","consider",".","token_indexers",":","``","Dict","[","str",",","TokenIndexer","]","``",",","optional","This","is","used","to","index","the","words","in","the","document",".","See",":","class",":","`","TokenIndexer","`",".","Default","is","``","{","``","tokens","''",":","SingleIdTokenIndexer","(",")","}","``","."]
docstr: Parameters
  ----------
  sentences : ``List[List[str]]``, required.
      A list of lists representing the tokenised words and sentences in the document.
  gold_clusters : ``Optional[List[List[Tuple[int, int]]]]``, optional (default = None)
      A list of all clusters in the document, represented as word spans. Each cluster
      contains some number of spans, which can be nested and overlap, but will never
      exactly match between clusters.
  
  Returns
  -------
  An ``Instance`` containing the following ``Fields``:
      text : ``TextField``
          The text of the full document.
      spans : ``ListField[SpanField]``
          A ListField containing the spans represented as ``SpanFields``
          with respect to the document text.
      span_labels : ``SequenceLabelField``, optional
          The id of the cluster which each possible span belongs to, or -1 if it does
           not belong to a cluster. As these labels have variable length (it depends on
           how many spans we are considering), we represent this a as a ``SequenceLabelField``
           with respect to the ``spans ``ListField``.
docstr_tok: ["Parameters","--","--","--","--","--","sentences",":","``","List","[","List","[","str","]","]","``",",","required",".","A","list","of","lists","representing","the","tokenised","words","and","sentences","in","the","document",".","gold_clusters",":","``","Optional","[","List","[","List","[","Tuple","[","int",",","int","]","]","]","]","``",",","optional","(","default","=","None",")","A","list","of","all","clusters","in","the","document",",","represented","as","word","spans",".","Each","cluster","contains","some","number","of","spans",",","which","can","be","nested","and","overlap",",","but","will","never","exactly","match","between","clusters",".","Returns","--","--","--","-","An","``","Instance","``","containing","the","following","``","Fields","``",":","text",":","``","TextField","``","The","text","of","the","full","document",".","spans",":","``","ListField","[","SpanField","]","``","A","ListField","containing","the","spans","represented","as","``","SpanFields","``","with","respect","to","the","document","text",".","span_labels",":","``","SequenceLabelField","``",",","optional","The","id","of","the","cluster","which","each","possible","span","belongs","to",",","or","-1","if","it","does","not","belong","to","a","cluster",".","As","these","labels","have","variable","length","(","it","depends","on","how","many","spans","we","are","considering",")",",","we","represent","this","a","as","a","``","SequenceLabelField","``","with","respect","to","the","``","spans","``","ListField","``","."]
code: def text_to_instance(
      self, sentences, gold_clusters=None  # type: ignore
  ):
      # pylint: disable=arguments-differ
      """
      Parameters
      ----------
      sentences : ``List[List[str]]``, required.
          A list of lists representing the tokenised words and sentences in the document.
      gold_clusters : ``Optional[List[List[Tuple[int, int]]]]``, optional (default = None)
          A list of all clusters in the document, represented as word spans. Each cluster
          contains some number of spans, which can be nested and overlap, but will never
          exactly match between clusters.
  
      Returns
      -------
      An ``Instance`` containing the following ``Fields``:
          text : ``TextField``
              The text of the full document.
          spans : ``ListField[SpanField]``
              A ListField containing the spans represented as ``SpanFields``
              with respect to the document text.
          span_labels : ``SequenceLabelField``, optional
              The id of the cluster which each possible span belongs to, or -1 if it does
               not belong to a cluster. As these labels have variable length (it depends on
               how many spans we are considering), we represent this a as a ``SequenceLabelField``
               with respect to the ``spans ``ListField``.
      """
      flattened_sentences = [
          self._normalize_word(word)
          for sentence in sentences
          for word in sentence
      ]
  
      metadata = {"original_text": flattened_sentences}
      if gold_clusters is not None:
          metadata["clusters"] = gold_clusters
  
      text_field = TextField(
          [Token(word) for word in flattened_sentences],
          self._token_indexers,
      )
  
      cluster_dict = {}
      if gold_clusters is not None:
          for cluster_id, cluster in enumerate(gold_clusters):
              for mention in cluster:
                  cluster_dict[tuple(mention)] = cluster_id
  
      spans = []
      span_labels = [] if gold_clusters is not None else None
  
      sentence_offset = 0
      for sentence in sentences:
          for start, end in enumerate_spans(
              sentence,
              offset=sentence_offset,
              max_span_width=self._max_span_width,
          ):
              if span_labels is not None:
                  if (start, end) in cluster_dict:
                      span_labels.append(cluster_dict[(start, end)])
                  else:
                      span_labels.append(-1)
  
              spans.append(SpanField(start, end, text_field))
          sentence_offset += len(sentence)
  
      span_field = ListField(spans)
      metadata_field = MetadataField(metadata)
  
      fields = {
          "text": text_field,
          "spans": span_field,
          "metadata": metadata_field,
      }
      if span_labels is not None:
          fields["span_labels"] = SequenceLabelField(
              span_labels, span_field
          )
  
      return Instance(fields)
  
file_path: magnitude/pymagnitude/third_party/allennlp/data/dataset_readers/coreference_resolution/conll.py
imports: from __future__ import absolute_import
  import logging
  import collections
  from allennlp.common.file_utils import cached_path
  from allennlp.data.dataset_readers.dataset_reader import DatasetReader
  from allennlp.data.fields import Field, ListField, TextField, SpanField, MetadataField, SequenceLabelField
  from allennlp.data.instance import Instance
  from allennlp.data.tokenizers import Token
  from allennlp.data.token_indexers import SingleIdTokenIndexer, TokenIndexer
  from allennlp.data.dataset_readers.dataset_utils import Ontonotes, enumerate_spans
label_desc: Use image node_id 3 for calling the ConllCorefReader obj's underlying member method code with example usage: obj.text_to_instance(sentences, gold_clusters) and returns: Instance