class_docstr: SquadIterator allows to iterate over examples in SQuAD-like datasets.
  SquadIterator is used to train 
  :class:`~deeppavlov.models.torch_bert.torch_transformers_squad:TorchTransformersSquad`.
  
  It extracts ``context``, ``question``, ``answer_text`` and ``answer_start`` position from dataset.
  Example from a dataset is a tuple of ``(context, question)`` and ``(answer_text, answer_start)``
  
  Attributes:
      train: train examples
      valid: validation examples
      test: test examples
class_docstr_tok: ["SquadIterator","allows","to","iterate","over","examples","in","SQuAD-like","datasets",".","SquadIterator","is","used","to","train",":","class",":","`","~deeppavlov.models.torch_bert.torch_transformers_squad",":","TorchTransformersSquad","`",".","It","extracts","``","context","``",",","``","question","``",",","``","answer_text","``","and","``","answer_start","``","position","from","dataset",".","Example","from","a","dataset","is","a","tuple","of","``","(","context",",","question",")","``","and","``","(","answer_text",",","answer_start",")","``","Attributes",":","train",":","train","examples","valid",":","validation","examples","test",":","test","examples"]
docstr: Extracts context, question, answer, answer_start from SQuAD data
  
  Args:
      data: data in squad format
  
  Returns:
      list of (context, question), (answer_text, answer_start)
      answer text and answer_start are lists
docstr_tok: ["Extracts","context",",","question",",","answer",",","answer_start","from","SQuAD","data","Args",":","data",":","data","in","squad","format","Returns",":","list","of","(","context",",","question",")",",","(","answer_text",",","answer_start",")","answer","text","and","answer_start","are","lists"]
code: def preprocess(
      self, data: Dict[str, Any], *args, **kwargs
  ) -> List[Tuple[Tuple[str, str], Tuple[List[str], List[int]]]]:
      """Extracts context, question, answer, answer_start from SQuAD data
  
      Args:
          data: data in squad format
  
      Returns:
          list of (context, question), (answer_text, answer_start)
          answer text and answer_start are lists
  
      """
      cqas = []
      if data:
          for article in data["data"]:
              for par in article["paragraphs"]:
                  context = par["context"]
                  for qa in par["qas"]:
                      q = qa["question"]
                      ans_text = []
                      ans_start = []
                      if qa["answers"]:
                          for answer in qa["answers"]:
                              ans_text.append(answer["text"])
                              ans_start.append(answer["answer_start"])
                      else:
                          ans_text = [""]
                          ans_start = [-1]
                      cqas.append(((context, q), (ans_text, ans_start)))
      return cqas
  
file_path: DeepPavlov/deeppavlov/dataset_iterators/squad_iterator.py
imports: import json
  from typing import Dict, Any, List, Tuple, Generator, Optional
  import numpy
  from deeppavlov.core.common.registry import register
  from deeppavlov.core.data.data_learning_iterator import DataLearningIterator
label_desc: Use image node_id 1 for calling the SquadIterator obj's underlying member method code with example usage: obj.preprocess(data) and returns: cqas