class_docstr: Speaker Classifier Teacher.
  
  This teacher is used for the RPA classifier training.
  
  This teacher should NOT be used directly.
class_docstr_tok: ["Speaker","Classifier","Teacher",".","This","teacher","is","used","for","the","RPA","classifier","training",".","This","teacher","should","NOT","be","used","directly","."]
docstr: Extract context, characters, and list of utterances from an episode.
  
  Additionally return initial start and end indices to use when constructing
  new eps.
  
  :param episode:
      list of examples
  :param exclude_from_context:
      list of context keys to exclude from the light context
  :param use_speech_prefix:
      if true, prepend label text with speech prefix.
  
  :return (context, characters, utterances):
      context: string context
      characters: dict mapping char key to character
      utterances: list of tuples (speaker_name, utterance, listener_name)
docstr_tok: ["Extract","context",",","characters",",","and","list","of","utterances","from","an","episode",".","Additionally","return","initial","start","and","end","indices","to","use","when","constructing","new","eps",".",":","param","episode",":","list","of","examples",":","param","exclude_from_context",":","list","of","context","keys","to","exclude","from","the","light","context",":","param","use_speech_prefix",":","if","true",",","prepend","label","text","with","speech","prefix",".",":","return","(","context",",","characters",",","utterances",")",":","context",":","string","context","characters",":","dict","mapping","char","key","to","character","utterances",":","list","of","tuples","(","speaker_name",",","utterance",",","listener_name",")"]
code: def _explode_episode(
      cls,
      episode: List[Message],
      exclude_from_context: List[str],
      use_speech_prefix: bool,
  ) -> Tuple[str, Dict[str, str], List[Tuple[str, str, str]]]:
      """
      Extract context, characters, and list of utterances from an episode.
  
      Additionally return initial start and end indices to use when constructing
      new eps.
  
      :param episode:
          list of examples
      :param exclude_from_context:
          list of context keys to exclude from the light context
      :param use_speech_prefix:
          if true, prepend label text with speech prefix.
  
      :return (context, characters, utterances):
          context: string context
          characters: dict mapping char key to character
          utterances: list of tuples (speaker_name, utterance, listener_name)
      """
      utterances = []
      context = episode[0]["text"]
      characters = extract_characters(context)
      me = characters["_self_name"]
      you = characters["_partner_name"]
      if not context.split("\n")[-1].startswith("_"):
          # begin conversation with partner
          utterances.append((you, context.split("\n")[-1], me))
          context = "\n".join(context.split("\n")[:-1])
  
      if exclude_from_context:
          context = "\n".join(
              [
                  c
                  for c in context.split("\n")
                  if not any(
                      c.startswith(x) for x in exclude_from_context
                  )
              ]
          )
  
      for i, ex in enumerate(episode):
          if i != 0:
              # skip context
              utterances.append((you, ex["text"], me))
          prefix = "_self_say " if use_speech_prefix else ""
          utterances.append((me, f"{prefix}{ex['labels'][0]}", you))
  
      return context, characters, utterances
  
imports: from abc import ABC
  from collections import deque
  import re
  from typing import Optional
  from parlai.core.build_data import modelzoo_path
  from parlai.core.message import Message
  from parlai.core.metrics import AverageMetric
  from parlai.core.opt import Opt
  from parlai.core.params import ParlaiParser
  from parlai.tasks.light_dialog.agents import SimpleMultiTeacher
  from parlai.utils.data import DatatypeHelper
  import parlai.utils.logging
  import copy
  import os
  import random
  import torch
  import torch.nn
  import torch.nn.functional
  from typing import List, Dict, Tuple
  from projects.light_whoami.task.utils import DEFAULT_DELIM, CONTEXT_KEYS, extract_characters, WHO_AM_I, WHO_ARE_YOU, SELF, PARTNER, WHO_IS_THIS, maybe_annotate
  import projects.light_whoami.task.mutators
label_desc: Use image node_id 6 for calling the SpeakerClassifierTeacher obj's underlying member method code with example usage: obj._explode_episode(cls, episode, exclude_from_context, use_speech_prefix) and returns: context,  characters,  utterances