code: def parse_cosmos(fn, reasoning, savefile):
      json_lines = []
      reasonings = {}
      with open(reasoning, "r") as f:
          json_lines = json.load(f)
  
      for json_line in json_lines:
          reasonings[json_line["key"]] = json_line
  
      with open(fn, "r") as f:
          csv_reader = csv.reader(f, delimiter=",")
  
          c = 0
          corrects = 0
          structs = []
          for line in csv_reader:
              if c == 0:
                  c += 1
                  continue
  
              struct = {}
              struct["key"] = line[0]
              struct["premise"] = line[1] + " " + line[2]
              correct_answer = int(line[7])
              if corrects > 100:
                  for t in range(4):
                      if t == correct_answer:
                          continue
                      struct["hypothesis"] = line[3 + t]
                      struct["answer"] = "no"
  
              else:
                  struct["hypothesis"] = line[3 + correct_answer]
                  struct["answer"] = "yes"
                  corrects += 1
  
              if "one of the above" in struct["hypothesis"]:
                  continue
  
              if struct["key"] in reasonings:
                  reasoning = reasonings[struct["key"]]["reasoning"]
                  struct["gpt-3"] = reasoning
                  structs.append(struct)
              else:
                  val = struct["key"]
                  print(f"No reasoning found for key {val}")
  
              if len(structs) > 200:
                  break
  
      write_to_file(structs, savefile)
  
file_path: ParlAI/projects/roscoe/roscoe_data/restore_annotated.py
imports: import json
  import csv
  import os
  import re
  import xmltodict
  from parlai.core.params import ParlaiParser
label_desc: Use image node_id 4 for calling a global function with example usage: parse_cosmos(fn, reasoning, savefile) without return types