class_docstr: Query for finetune query generator.
  
  human_gold: human written search query that lead to perfect utterance,
      e.g better_search_query->perfect; better_search_query -> better_search_doc -> perfect;
          better_search_query -> better_search_doc -> better_response -> perfect
  human_bronze: human written search query that doesn't belong to perfect utterance
  bot_gold: bot search queries that leads to perfect utterance e.g. better_doc -> perfect
class_docstr_tok: ["Query","for","finetune","query","generator",".","human_gold",":","human","written","search","query","that","lead","to","perfect","utterance",",","e.g","better_search_query-",">","perfect",";","better_search_query","-",">","better_search_doc","-",">","perfect",";","better_search_query","-",">","better_search_doc","-",">","better_response","-",">","perfect","human_bronze",":","human","written","search","query","that","does","n't","belong","to","perfect","utterance","bot_gold",":","bot","search","queries","that","leads","to","perfect","utterance","e.g",".","better_doc","-",">","perfect"]
code: def _extract_feedback(self, episode):
      history = []
      res = {
          "human_gold": [],
          "human_bronze": [],
          "bot_gold": [],
          "bot_failure": [],
      }
  
      for turn in episode:
          history.append(normalize_reply(turn["text"]))
          human_provided_queries = turn["human_revision"][
              "search_query"
          ]
          per_turn_res = {
              "human_gold": [],
              "human_bronze": [],
              "bot_gold": [],
              "bot_failure": [],
          }
          if (
              turn["last_nonperfect_feedback"]
              == FeedbackType.CORRECT_SEARCH_QUERY.value
              or (
                  # ..., better_search_query, better_search_doc, perfect
                  len(turn["feedback_chain"]) >= 3
                  and turn["feedback_chain"][-3]
                  == FeedbackType.CORRECT_SEARCH_QUERY.value
                  and turn["feedback_chain"][-2]
                  == FeedbackType.CORRECT_DOC.value
              )
              or (
                  # ..., better_search_query, better_search_doc, better_others, perfect
                  len(turn["feedback_chain"]) >= 4
                  and turn["feedback_chain"][-4]
                  == FeedbackType.CORRECT_SEARCH_QUERY.value
                  and turn["feedback_chain"][-3]
                  == FeedbackType.CORRECT_DOC.value
                  and turn["feedback_chain"][-2]
                  == FeedbackType.CORRECT_RESPONSE.value
              )
          ):
              per_turn_res["human_gold"] = [human_provided_queries[-1]]
          per_turn_res["human_bronze"] = [
              q
              for q in human_provided_queries
              if q not in per_turn_res["human_gold"]
          ]
          per_turn_res["bot_gold"] = turn["bot_gold"].get(
              "search_query", []
          )
          per_turn_res["bot_failure"] = turn["bot_modular_failure"].get(
              "search_query", []
          )
  
          for source in per_turn_res:
              for q in per_turn_res[source]:
                  res[source].append(
                      {
                          "text": "\n".join(history),
                          "labels": [normalize_reply(q)],
                      }
                  )
          history.append(normalize_reply(turn["labels"][0]))
      return res
  
imports: import os
  import copy
  import json
  import random
  from typing import Optional
  from parlai.utils.misc import warn_once
  from parlai.utils.data import DatatypeHelper
  from parlai.core.opt import Opt
  from parlai.core.teachers import DialogTeacher
  from parlai.core.params import ParlaiParser
  from parlai.core.message import Message
  from parlai.utils.io import PathManager
  from parlai.tasks.wizard_of_internet import constants
  from .mutators import normalize_reply, get_knowledge_appended_context, get_knowledge_sentence_with_special_tokens_only
  from .build import build
  from .constants import FeedbackType, TITLE_PASSAGE_DELIMITER, OK_LABEL, NOT_OK_LABEL
label_desc: Use image node_id 4 for calling the QueryTeacher obj's underlying member method code with example usage: obj._extract_feedback(episode) and returns: res