class_docstr: Reads a JSON-formatted SQuAD file and returns a ``Dataset`` where the ``Instances`` have four
  fields: ``question``, a ``TextField``, ``passage``, another ``TextField``, and ``span_start``
  and ``span_end``, both ``IndexFields`` into the ``passage`` ``TextField``.  We also add a
  ``MetadataField`` that stores the instance's ID, the original passage text, gold answer strings,
  and token offsets into the original passage, accessible as ``metadata['id']``,
  ``metadata['original_passage']``, ``metadata['answer_texts']`` and
  ``metadata['token_offsets']``.  This is so that we can more easily use the official SQuAD
  evaluation script to get metrics.
  
  Parameters
  ----------
  tokenizer : ``Tokenizer``, optional (default=``WordTokenizer()``)
      We use this ``Tokenizer`` for both the question and the passage.  See :class:`Tokenizer`.
      Default is ```WordTokenizer()``.
  token_indexers : ``Dict[str, TokenIndexer]``, optional
      We similarly use this for both the question and the passage.  See :class:`TokenIndexer`.
      Default is ``{"tokens": SingleIdTokenIndexer()}``.
code: def text_to_instance(
      self,  # type: ignore
      question_text,
      passage_text,
      char_spans=None,
      answer_texts=None,
      passage_tokens=None,
  ):
      # pylint: disable=arguments-differ
      if not passage_tokens:
          passage_tokens = self._tokenizer.tokenize(passage_text)
      char_spans = char_spans or []
  
      # We need to convert character indices in `passage_text` to token indices in
      # `passage_tokens`, as the latter is what we'll actually use for supervision.
      token_spans = []
      passage_offsets = [
          (token.idx, token.idx + len(token.text))
          for token in passage_tokens
      ]
      for char_span_start, char_span_end in char_spans:
          (span_start, span_end), error = util.char_span_to_token_span(
              passage_offsets, (char_span_start, char_span_end)
          )
          if error:
              logger.debug("Passage: %s", passage_text)
              logger.debug("Passage tokens: %s", passage_tokens)
              logger.debug("Question text: %s", question_text)
              logger.debug(
                  "Answer span: (%d, %d)",
                  char_span_start,
                  char_span_end,
              )
              logger.debug("Token span: (%d, %d)", span_start, span_end)
              logger.debug(
                  "Tokens in answer: %s",
                  passage_tokens[span_start : span_end + 1],
              )
              logger.debug(
                  "Answer: %s",
                  passage_text[char_span_start:char_span_end],
              )
          token_spans.append((span_start, span_end))
  
      return util.make_reading_comprehension_instance(
          self._tokenizer.tokenize(question_text),
          passage_tokens,
          self._token_indexers,
          passage_text,
          token_spans,
          answer_texts,
      )
  
file_path: magnitude/pymagnitude/third_party/allennlp/data/dataset_readers/reading_comprehension/squad.py
imports: from __future__ import with_statement
  from __future__ import absolute_import
  import json
  import logging
  from allennlp.common.file_utils import cached_path
  from allennlp.data.dataset_readers.dataset_reader import DatasetReader
  from allennlp.data.instance import Instance
  from allennlp.data.dataset_readers.reading_comprehension import util
  from allennlp.data.token_indexers import SingleIdTokenIndexer, TokenIndexer
  from allennlp.data.tokenizers import Token, Tokenizer, WordTokenizer
  from io import open
label_desc: Use image node_id 3 for calling the SquadReader obj's underlying member method code with example usage: obj.text_to_instance(question_text, passage_text, char_spans, answer_texts, passage_tokens) and returns: util