class_docstr: RagModel.
  
  The RagModel operates in the following phases:
  1) retrieve:    given a tokenized query, return relevant documents
  2) expand:      given queries and documents, expand the inputs n_docs times,
                  concatenating each document with a relevant context
  3) encode:      given expanded input, encode into encoder representations
  4) decoding:    given encoder outputs, compute n_docs decoder representations for
                  each batch item.
  5) marginalize: given the decoded representations, marginalize over the documents
  appropriately.
  
  The RagModel overloads the `encoder` and `decoder` attributes of your standard
  `TorchGeneratorModel` to accomplish the five phases above.
code: def __init__(self, opt, dictionary, retriever_shared=None):
      from parlai.agents.rag.rag import RAG_MODELS
  
      self.pad_idx = dictionary[dictionary.null_token]
      self.start_idx = dictionary[dictionary.start_token]
      self.end_idx = dictionary[dictionary.end_token]
      super().__init__(self.pad_idx, self.start_idx, self.end_idx)
      self.fp16 = (
          not opt["no_cuda"]
          and torch.cuda.is_available()
          and opt.get("fp16", False)
      )
      self.dict = dictionary
      self.embeddings = create_embeddings(
          dictionary, opt["embedding_size"], self.pad_idx
      )
      # attrs
      self.rag_model_type = opt["rag_model_type"]
      self._rag_model_interface = RAG_MODELS[self.rag_model_type](
          opt, self.pad_idx
      )
      self.generation_model = opt["generation_model"]
      self.n_extra_positions = opt["n_extra_positions"]
      self.n_positions = (
          get_n_positions_from_options(opt) + opt["n_extra_positions"]
      )
      assert opt["n_extra_positions"] >= 0
      self.expanded_input_truncate = min(
          opt["text_truncate"] or opt["truncate"],
          get_n_positions_from_options(opt),
      )
      if self.n_extra_positions > 0:
          # This attribute is overloaded.
          # when n_extra_positions == 0, it is the truncation of the full expanded input
          # when >0, it is the maximum length of the knowledge tokens.
          self.expanded_input_truncate = self.n_extra_positions
      self.min_doc_token_length = opt["min_doc_token_length"]
  
      # modules
      self.retriever = self.build_retriever(
          opt, dictionary, retriever_shared
      )
      self.seq2seq_encoder = self.build_encoder(
          opt,
          dictionary=dictionary,
          embedding=self.embeddings,
          padding_idx=self.pad_idx,
      )
      self.seq2seq_decoder = self.build_decoder(
          opt,
          embedding=self.embeddings,
          dictionary=dictionary,
          padding_idx=self.pad_idx,
      )
  
imports: import torch
  import torch.cuda
  import torch.nn
  import torch.nn.functional
  from typing import Any, Tuple, Dict, Optional, List, Union, Type
  from parlai.agents.hugging_face.t5 import ParlaiT5Encoder, ParlaiT5Decoder, build_t5, set_device
  from parlai.agents.transformer.modules import TransformerEncoder, TransformerDecoder, get_n_positions_from_options, create_embeddings
  from parlai.core.dict import DictionaryAgent
  from parlai.core.opt import Opt
  from parlai.core.torch_generator_agent import TorchGeneratorModel
  from parlai.utils.torch import padded_tensor
  from parlai.agents.rag.retrievers import RagRetriever, retriever_factory, Document
label_desc: Use image node_id 1 to create a new RagModel object from inherited base classes: TorchGeneratorModel with example: obj = RagModel(opt, dictionary, retriever_shared)