class_docstr: ALL LIGHT Teacher: combines all gender bias mitigation methods described in.
  
  <https://arxiv.org/abs/1911.03842>.
  
  This teacher combines methods for gender bias mitigation in
  dialogue generation on the LIGHT dialogue task, including:
  - Adding more positive data (Pos Data):`--add-new-data`
  - Conditional training (Bias Ctrl): `--add-conditional`
  - Counterfactual Data Augmentation (CDA): `--add-counterfactual`
  
  For more information, please see our projects page:
  <https://parl.ai/projects/genderation_bias/>
class_docstr_tok: ["ALL","LIGHT","Teacher",":","combines","all","gender","bias","mitigation","methods","described","in",".","<","https",":","\/\/arxiv.org\/abs\/1911.03842",">",".","This","teacher","combines","methods","for","gender","bias","mitigation","in","dialogue","generation","on","the","LIGHT","dialogue","task",",","including",":","-","Adding","more","positive","data","(","Pos","Data",")",":","`","--","add-new-data","`","-","Conditional","training","(","Bias","Ctrl",")",":","`","--","add-conditional","`","-","Counterfactual","Data","Augmentation","(","CDA",")",":","`","--","add-counterfactual","`","For","more","information",",","please","see","our","projects","page",":","<","https",":","\/\/parl.ai\/projects\/genderation_bias\/",">"]
docstr: Load original LIGHT dataset.
docstr_tok: ["Load","original","LIGHT","dataset","."]
code: def _setup_data(self, opt):
      """
      Load original LIGHT dataset.
      """
      # Add new data?
      dt = opt["datatype"].split(":")[0]
  
      orig_episodes = OrigLightTeacher(opt).episodes
      if self.add_new_data:
          new_data = self._get_new_data(opt)
          total_data = orig_episodes + new_data
          self.fixed_random.shuffle(total_data)
          orig_episodes = total_data
  
      # Flatten this data
      flat_episodes = []
      for ep in orig_episodes:
          # flatten the episode into 1-example episodes with context
          flattened_ep = flatten(
              ep, -1, include_labels=True, delimiter="\n"
          )
          flat_episodes += flattened_ep
  
      # Counterfactual?
      if self.add_counterfactual and dt != "test":
          with PathManager.open(
              os.path.join(_path(opt), COUNTERFACTUALS), "rb"
          ) as f:
              self.swap_dct = json.load(f)
  
          new_episodes = []
          for ex in flat_episodes:
              new_ex = self._flip_ex(ex)
              ex[
                  "counterfactual"
              ] = False  # mark which episode is swapped
              new_ex["counterfactual"] = True
              # add both old and new examples
              new_episodes.append(ex)
              new_episodes.append(new_ex)
  
          flat_episodes = new_episodes
  
      # Conditional training?
      bucket_percentages = {}
      new_episodes = []
      for ex in flat_episodes:
          label_type = "labels" if "labels" in ex else "eval_labels"
          label = ex[label_type][0]
          # get bucket for label
          bucket_key = self.get_bucket(label)
          # update the bucket percentages
          bucket_percentages.setdefault(bucket_key, 0)
          bucket_percentages[bucket_key] += 1
          # append this bucket to the text field
          if self.add_conditional:
              if self.force_conditional is None:
                  new_text = ex["text"] + "\n" + bucket_key
              else:
                  # force the model to see a specific bucket every time
                  # NOTE: we still track the original bucket that the
                  # text was supposed to fall into
                  new_text = ex["text"] + self.force_conditional
              ex.force_set("text", new_text)
          ex["bucket"] = bucket_key
          if self.bucket_only is None or self.bucket_only == bucket_key:
              new_episodes.append(ex)
  
      # Summarize the bucket distribution
      print("Distribution of bins:")
      total = sum(bucket_percentages.values())
      strs = []
      for k, v in bucket_percentages.items():
          pct = round((v / total) * 100, 2)
          strs.append(f"{k}: {pct}%")
      strs = sorted(strs)
      for string in strs:
          print(string)
  
      return new_episodes
  
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 9 for calling the LightGenderTeacher obj's underlying member method code with example usage: obj._setup_data(opt) and returns: new_episodes