class_docstr: DatasetBuilder for squad_question_generation dataset.
class_docstr_tok: ["DatasetBuilder","for","squad_question_generation","dataset","."]
docstr: Yields question generation examples.
  
  Args:
    squad_data_path: Path to SQuAD json file.
    mapping_path:  File with SQuAD map id for the example in Zhou et al.
      splits.
    qgen_data_path:  File with examples in "TokenizedInputSentence\t
      AnswerStartAndEndPosition\tParsingTreeOfInputSentence\t
      PoSTagOfInputSentence\tNERTagsOfInputSentence\tTokenizedQuestion\t
      UntokenizedInputSentence\tAnswerStartCharIndex\tAnswer\t
      UntokenizedQuestion" format per line, for the Zhou et al. splits.
  
  Yields:
    key and example dict.
docstr_tok: ["Yields","question","generation","examples",".","Args",":","squad_data_path",":","Path","to","SQuAD","json","file",".","mapping_path",":","File","with","SQuAD","map","id","for","the","example","in","Zhou","et","al",".","splits",".","qgen_data_path",":","File","with","examples","in","``","TokenizedInputSentence\\t","AnswerStartAndEndPosition\\tParsingTreeOfInputSentence\\t","PoSTagOfInputSentence\\tNERTagsOfInputSentence\\tTokenizedQuestion\\t","UntokenizedInputSentence\\tAnswerStartCharIndex\\tAnswer\\t","UntokenizedQuestion","''","format","per","line",",","for","the","Zhou","et","al",".","splits",".","Yields",":","key","and","example","dict","."]
code: def _generate_examples(
      self, squad_data_path, mapping_path=None, qgen_data_path=None
  ):
      r"""Yields question generation examples.
  
      Args:
        squad_data_path: Path to SQuAD json file.
        mapping_path:  File with SQuAD map id for the example in Zhou et al.
          splits.
        qgen_data_path:  File with examples in "TokenizedInputSentence\t
          AnswerStartAndEndPosition\tParsingTreeOfInputSentence\t
          PoSTagOfInputSentence\tNERTagsOfInputSentence\tTokenizedQuestion\t
          UntokenizedInputSentence\tAnswerStartCharIndex\tAnswer\t
          UntokenizedQuestion" format per line, for the Zhou et al. splits.
  
      Yields:
        key and example dict.
      """
      if self.builder_config.name == "split_du":
          # The file format slightly differs from the original SQuAD JSON format.
          with epath.Path(squad_data_path).open() as f:
              squad_data = json.load(f)
              for article in squad_data:
                  for paragraph in article["paragraphs"]:
                      context = paragraph["context"]
                      for qa in paragraph["qas"]:
                          yield qa["id"], {
                              _CONTEXT_PASSAGE: context,
                              _ANSWER: qa["answers"][0]["text"],
                              _QUESTION: qa["question"],
                          }
      elif self.builder_config.name == "split_zhou":
          squad_data = {}
          for k, ex in qa_utils.generate_squadlike_examples(
              squad_data_path
          ):
              squad_data[k] = ex
          with tf.io.gfile.GFile(mapping_path, "r") as mapping_file:
              with tf.io.gfile.GFile(
                  qgen_data_path, "r"
              ) as qgen_data_file:
                  for ex_id, (squad_id, qgen_data) in enumerate(
                      zip(
                          mapping_file.read().splitlines(),
                          qgen_data_file.read().splitlines(),
                      )
                  ):
                      (
                          _,
                          _,
                          _,
                          _,
                          _,
                          _,
                          context_sentence,
                          _,
                          answer,
                          question,
                      ) = qgen_data.split("\t")
                      context_passage = squad_data[squad_id]["context"]
                      yield str(ex_id).zfill(7), {
                          _CONTEXT_SENTENCE: context_sentence,
                          _CONTEXT_PASSAGE: context_passage,
                          _ANSWER: answer,
                          _QUESTION: question,
                      }
  
file_path: datasets/tensorflow_datasets/text/squad_question_generation/squad_question_generation.py
imports: import json
  import os
  import textwrap
  from etils import epath
  from tensorflow_datasets.core.utils.lazy_imports_utils import tensorflow
  import tensorflow_datasets.public_api
  from tensorflow_datasets.question_answering import qa_utils
label_desc: Use image node_id 3 for calling the SquadQuestionGeneration obj's underlying member method code with example usage: obj._generate_examples(squad_data_path, mapping_path, qgen_data_path) without return types