code: def flatten(
      episode, context_length, include_labels=True, delimiter="\n"
  ):
      """
      Flatten the data into single example episodes.
  
      This is used to make conditional training easier and for a fair comparison of
      methods.
      """
      context = deque(
          maxlen=context_length if context_length > 0 else None
      )
      new_episode = []
  
      for ex in episode:
          context.append(ex.get("text", ""))
          # add context
          if len(context) > 1:
              ex.force_set("text", delimiter.join(context))
          # set episode_done to be True
          ex.force_set("episode_done", True)
          labels = ex.get("labels", ex.get("eval_labels", None))
          if labels is not None and include_labels:
              context.append(random.choice(labels))
  
          new_episode.append(ex)
  
      return new_episode
  
imports: from typing import Optional
  from parlai.core.params import ParlaiParser
  from parlai.core.opt import Opt
  from parlai.core.message import Message
  from parlai.core.teachers import FixedDialogTeacher
  from parlai.tasks.light_dialog.agents import DefaultTeacher
  from parlai.tasks.light_genderation_bias.build import build
  from parlai.utils.io import PathManager
  from collections import deque
  from copy import deepcopy
  import csv
  import json
  import os
  import random
label_desc: Use image node_id 6 for calling a global function with example usage: flatten(episode, context_length, include_labels, delimiter) and returns: new_episode