class_docstr: The QueryGenerator is a wrapper around a generator model.
  
  This model can be trained for both dataset classification and search query
  generation.
class_docstr_tok: ["The","QueryGenerator","is","a","wrapper","around","a","generator","model",".","This","model","can","be","trained","for","both","dataset","classification","and","search","query","generation","."]
code: def __init__(self, opt: Opt):
      self.opt = opt
      self.agents = []
      self.agent_dict = None
      self.generations = []
      self.input_type = "Search"
      self.knowledge_access_method = KnowledgeAccessMethod(
          opt["knowledge_access_method"]
      )
      model_file = modelzoo_path(
          opt["datapath"], opt["query_generator_model_file"]
      )
      if (
          self.knowledge_access_method
          is KnowledgeAccessMethod.SEARCH_ONLY
          and "blenderbot2/query_generator/model" in model_file
      ):
          raise ValueError(
              "You cannot use the blenderbot2 query generator with search_only. Please "
              "consider setting --query-generator-model-file zoo:sea/bart_sq_gen/model "
              "instead."
          )
      if model_file and os.path.exists(model_file):
          logging.info(
              f"Building Query Generator from file: {model_file}"
          )
          logging.disable()
          overrides: Dict[str, Any] = {"skip_generation": False}
          overrides["inference"] = opt["query_generator_inference"]
          overrides["beam_size"] = opt.get(
              "query_generator_beam_size", 3
          )
          overrides["beam_min_length"] = opt.get(
              "query_generator_beam_min_length", 2
          )
          overrides["model_parallel"] = opt["model_parallel"]
          overrides["no_cuda"] = opt["no_cuda"]
          if self.opt["query_generator_truncate"] > 0:
              overrides["text_truncate"] = self.opt[
                  "query_generator_truncate"
              ]
              overrides["truncate"] = self.opt[
                  "query_generator_truncate"
              ]
          base_agent = create_agent_from_model_file(
              model_file, opt_overrides=overrides
          )
          assert isinstance(base_agent, TorchAgent)
          self.agents = [base_agent]
          bsz = max(
              opt.get("batchsize") or 1, opt.get("eval_batchsize") or 1
          )
          rag_turn_n_turns = opt.get("rag_turn_n_turns", 1)
          if bsz > 1 or rag_turn_n_turns > 1:
              self.agents += [
                  create_agent_from_shared(self.agents[0].share())
                  for _ in range((bsz * rag_turn_n_turns) - 1)
              ]
          self.agent_dict = self.agents[0].build_dictionary()
          logging.enable()
  
imports: from enum import Enum, auto
  import os
  import string
  import time
  import torch
  import torch.nn
  from typing import List, Tuple, Dict, Optional, Any
  from parlai.agents.rag.retrievers import clean_vec
  from parlai.core.agents import create_agent_from_model_file, create_agent_from_shared
  from parlai.core.build_data import modelzoo_path
  from parlai.core.dict import DictionaryAgent
  from parlai.core.message import Message
  from parlai.core.opt import Opt
  from parlai.core.torch_agent import TorchAgent
  from parlai.tasks.msc.agents import NOPERSONA
  import parlai.utils.logging
label_desc: Use image node_id 1 to create a new QueryGenerator object from inherited base classes: BB2SubmoduleMixin with example: obj = QueryGenerator(opt)