class_docstr: Predict the gender of character given the dialogue utterance.
class_docstr_tok: ["Predict","the","gender","of","character","given","the","dialogue","utterance","."]
code: def _setup_data(self, opt):
      counts = {
          "partner": {
              gend_utils.UNKNOWN: 0,
              gend_utils.FEM: 0,
              gend_utils.MASC: 0,
          },
          "self": {
              gend_utils.UNKNOWN: 0,
              gend_utils.FEM: 0,
              gend_utils.MASC: 0,
          },
      }
  
      dt = opt["datatype"].split(":")[0]
      if dt == "test":
          warn_once("No test set; switching to valid")
          dt = "valid"
  
      # build data
      print("[ Building data ... ]")
      new_eps = []
      orig_teacher = OrigConvai2Teacher(opt)
      total_exs = orig_teacher.num_examples()
      num_exs = 0
      while num_exs < total_exs:
          current_episode = []
          episode_done = False
  
          while not episode_done:
              # TODO: eventually all teachers should return Messages, so
              # we should assert this
              action = Message(orig_teacher.act())
              current_episode.append(action)
              episode_done = action.get("episode_done", False)
              num_exs += 1
  
          # now we have the entire episode,... do something
          first_ex = current_episode[0]
          first_ex_text = []
          partner_persona = []
          your_persona = []
          for line in first_ex["text"].split("\n"):
              # NOTE: we flip "your" and "partner" here since we are taking the 'text'
              # field instead of the 'label'
              if "partner's persona: " in line:
                  your_persona.append(
                      line.split("partner's persona: ")[1]
                  )
              elif "your persona: " in line:
                  partner_persona.append(
                      line.split("your persona: ")[1]
                  )
              else:
                  first_ex_text.append(line)
  
          your, your_prob, partner, partner_prob = self.get_genders(
              your_persona, partner_persona
          )
  
          for i, ex in enumerate(current_episode):
              counts["self"][your] += 1
              counts["partner"][partner] += 1
              if i == 0:
                  text = "\n".join(first_ex_text)
              else:
                  text = ex["text"]
              new_ex = {
                  "text": text,
                  "episode_done": True,
                  "your_persona": "\n".join(your_persona),
                  "partner_persona": "\n".join(partner_persona),
                  "id": "ConvAI2 Gender",
              }
              if not self.use_probably:
                  new_ex["partner_prob"] = partner_prob
                  new_ex["your_prob"] = your_prob
  
              if your is not None and self.labels_to_use != "partner":
                  # Get the your task
                  labels = [f"SELF:{your}"]
                  your_ex = deepcopy(new_ex)
                  your_ex["labels"] = labels
                  your_ex["class_type"] = "self"
                  new_eps.append(your_ex)
  
              if partner is not None and self.labels_to_use != "self":
                  # Get the partner task
                  labels = [f"PARTNER:{partner}"]
                  partner_ex = deepcopy(new_ex)
                  partner_ex["labels"] = labels
                  partner_ex["class_type"] = "partner"
                  new_eps.append(partner_ex)
  
      if self.labels_to_use == "all" and self.add_unknown_classes:
          # load about data
          all_about_data = gend_utils.get_inferred_about_data(
              self.opt["task"], self.opt
          )
          sample_rate = self.opt["unknown_temp"]
          if sample_rate < 1.0:
              to_samp = int(sample_rate * len(all_about_data))
              sampled = random.sample(all_about_data, to_samp)
              new_eps += sampled
          else:
              new_eps += all_about_data
  
      if self.is_train:
          random.shuffle(new_eps)
  
      self.data = new_eps
      print(f"Missing cnt: {self.missing_cnt} / {len(self.data) * 2}")
      for x in ["self", "partner"]:
          print(f"Totals for {x}:")
          subtot = sum(counts[x].values())
          for k, v in counts[x].items():
              print(f"\t{k}: {v} ({v / subtot})")
  
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.convai2.agents import BothTeacher
  from parlai.tasks.md_gender.build import build
  from parlai.utils.misc import warn_once
  import parlai.tasks.md_gender.utils
  from copy import deepcopy
  import json
  import random
  import os
label_desc: Use image node_id 8 for calling the Convai2Teacher obj's underlying member method code with example usage: obj._setup_data(opt) without return types