code: def convert_to_dataset(list_of_dicts):
      try:
          from datasets import Dataset, load_dataset
      except ImportError:
          raise ImportError(
              "The datasets package is required for fine-tuning QA models: pip install datasets"
          )
  
      new_list = []
      for d in list_of_dicts:
          if (
              "question" not in d
              or "context" not in d
              or "answers" not in d
          ):
              raise ValueError(
                  'All dictionaries in list must have the following keys: "question", "context", "answers"'
              )
          q = d["question"].strip()
          c = d["context"].strip()
          a = (
              d["answers"].strip()
              if isinstance(d["answers"], str)
              else d["answers"]
          )
          if a is None:
              answers = {"text": [], "answer_start": []}
          elif isinstance(a, dict):
              ans_start = a["answer_start"]
              ans_text = a["text"]
              answers = {"text": ans_text, "answer_start": ans_start}
          elif isinstance(a, str):
              ans_start = c.index(a)
              if ans_start < 0:
                  raise ValueError(
                      "Could not locate answer in context: %s" % (d)
                  )
              ans_start = [ans_start]
              answers = {"text": [a], "answer_start": ans_start}
          else:
              raise ValueError(
                  'Value for "answers" key must be a string, dictionary, or None'
              )
          new_d = {"question": q, "context": c, "answers": answers}
          new_list.append(new_d)
      dataset = Dataset.from_pandas(pd.DataFrame(new_list))
  
      # uncomment to test with squad sample
      # datasets = load_dataset('squad')
      # td = datasets['train']
      # td = Dataset.from_pandas(td.to_pandas().head(100))
      # return td
      return dataset
  
file_path: ktrain/ktrain/text/qa/qa_finetuner.py
imports: import warnings
  import pandas
  import tensorflow
label_desc: Use image node_id 1 for calling a global function with example usage: convert_to_dataset(list_of_dicts) and returns: dataset