class_docstr: Abstract data loader.
class_docstr_tok: ["Abstract","data","loader","."]
docstr: Parses into TodStructuredEpisode.
code: def setup_episodes(self, fold):
      """
      Parses into TodStructuredEpisode.
      """
      chunks, api_schema_raw = self._load_data(fold)
      api_schemas_machine = self._parse_to_api_schema(api_schema_raw)
      episodes = []
      for _, row in chunks.iterrows():
          utterances = row["utterances"][:]
          if not all(
              [
                  x.get("speaker") == "ASSISTANT"
                  or x.get("speaker") == "USER"
                  for x in utterances
              ]
          ):
              # there's an example or two that causes things to infinite loop. >.>
              continue
          idx = 0
          rounds = []
          goal_calls = []
          if (
              len(utterances) > 0
              and utterances[0]["speaker"] == "ASSISTANT"
          ):
              (
                  idx,
                  sys_utt,
                  _,
              ) = self._get_utterance_and_slots_for_speaker(
                  "ASSISTANT", utterances, idx
              )
  
              turns = self._get_turns_from_parsed(
                  SILENCE_TOKEN, {}, {}, sys_utt
              )
              for t in turns:
                  rounds.append(t)
  
          while idx < len(utterances):
              (
                  idx,
                  user_utt,
                  user_slots,
              ) = self._get_utterance_and_slots_for_speaker(
                  "USER", utterances, idx
              )
              (
                  idx,
                  sys_utt,
                  system_slots,
              ) = self._get_utterance_and_slots_for_speaker(
                  "ASSISTANT", utterances, idx
              )
              # The annotations in this dataset don't make sense as api responses but... we'll just roll.
              turns = self._get_turns_from_parsed(
                  user_utt, user_slots, system_slots, sys_utt
              )
              for t in turns:
                  rounds.append(t)
          apis = []
          for candidate_api in api_schemas_machine:
              if candidate_api in row["instruction_id"]:
                  apis.append(api_schemas_machine[candidate_api])
          episode = tod.TodStructuredEpisode(
              api_schemas_machine=apis,
              goal_calls_machine=goal_calls,
              rounds=rounds,
              delex=self.opt.get("delex", False),
          )
          episodes.append(episode)
      return episodes
  
imports: from parlai.core.params import ParlaiParser
  import os
  import pandas
  from parlai.core.opt import Opt
  import parlai.core.tod.tod_core
  from typing import Optional
  from parlai.utils.data import DatatypeHelper
  from parlai.utils.io import PathManager
  import parlai.tasks.taskmaster.build
  import parlai.core.tod.tod_agents
  from parlai.core.teachers import FixedDialogTeacher
  from .None import tm_utils
  import json
label_desc: Use image node_id 8 for calling the Taskmaster1Parser obj's underlying member method code with example usage: obj.setup_episodes(fold) and returns: episodes