code: def flatten_and_classify(
      episode: List[Message],
      context_length: int,
      word_lists: Tuple[List[str], List[str]],
      include_labels: bool = True,
      delimiter: str = "\n",
  ):
      """
      Flatten the dialogue history of an episode, explode into N new examples.
  
      Additionally, add control token corresponding to gender identified in the
      episode.
  
      :param episode:
          list of examples to flatten
      :param context_length:
          max number of utterances to use while flattening
      :param word_lists:
          tuple of lists for male-specific and female-specific words
      :param include_labels:
          whether to include labels while flattening
      :param delimiter:
          delimiter to use while flattening
      """
      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))
  
          # word list
          control_tok = get_word_list_token(
              random.choice(labels), word_lists
          )
          ex.force_set("text", ex["text"] + " " + control_tok)
          new_episode.append(ex)
  
      return new_episode
  
file_path: ParlAI/parlai/tasks/genderation_bias/utils.py
imports: from collections import deque
  import random
  from parlai.core.loader import load_teacher_module
  from parlai.core.message import Message
  from parlai.core.opt import Opt
  from typing import List, Tuple
label_desc: Use image node_id 3 for calling a global function with example usage: flatten_and_classify(episode, context_length, word_lists, include_labels, delimiter) and returns: new_episode