code: def write_out_candidates(chats, dpath, dtype):
      cands["speech"] = []
      for chat in chats:
          dialogue_turns = chat["dialogue"]
          pos_cands = [
              t["text"] for t in dialogue_turns if t["id"] == "human"
          ]
          cands["speech"] += pos_cands
      fw = io.open(
          os.path.join(dpath, "speech_" + dtype + "_cands.txt"), "w"
      )
      for k in cands["speech"]:
          fw.write(k + "\n")
      fw.close
  
imports: import random
  import io
  import os
  import json
  from parlai.utils.misc import msg_to_str
label_desc: Use image node_id 8 for calling a global function with example usage: write_out_candidates(chats, dpath, dtype) without return types