class_docstr: Poly-encoder model.
  
  See https://arxiv.org/abs/1905.01969 for more details
class_docstr_tok: ["Poly-encoder","model",".","See","https",":","\/\/arxiv.org\/abs\/1905.01969","for","more","details"]
docstr: Forward pass of the model.
  
  Due to a limitation of parlai, we have to have one single model
  in the agent. And because we want to be able to use data-parallel,
  we need to have one single forward() method.
  Therefore the operation_type can be either 'encode' or 'score'.
  
  :param ctxt_inputs:
      Dictionary of context inputs. Will include at least 'ctxt_tokens',
      containing tokenized contexts
  :param cand_tokens:
      tokenized candidates
  :param ctxt_rep:
      (bsz x num_codes x hsz)
      encoded representation of the context. If self.type == 'codes', these
      are the context codes. Otherwise, they are the outputs from the
      encoder
  :param ctxt_rep_mask:
      mask for ctxt rep
  :param cand_rep:
      encoded representation of the candidates
docstr_tok: ["Forward","pass","of","the","model",".","Due","to","a","limitation","of","parlai",",","we","have","to","have","one","single","model","in","the","agent",".","And","because","we","want","to","be","able","to","use","data-parallel",",","we","need","to","have","one","single","forward","(",")","method",".","Therefore","the","operation_type","can","be","either","'encode","'","or","'score","'",".",":","param","ctxt_inputs",":","Dictionary","of","context","inputs",".","Will","include","at","least","'ctxt_tokens","'",",","containing","tokenized","contexts",":","param","cand_tokens",":","tokenized","candidates",":","param","ctxt_rep",":","(","bsz","x","num_codes","x","hsz",")","encoded","representation","of","the","context",".","If","self.type","==","'codes","'",",","these","are","the","context","codes",".","Otherwise",",","they","are","the","outputs","from","the","encoder",":","param","ctxt_rep_mask",":","mask","for","ctxt","rep",":","param","cand_rep",":","encoded","representation","of","the","candidates"]
code: def forward(
      self,
      cand_tokens=None,
      ctxt_rep=None,
      ctxt_rep_mask=None,
      cand_rep=None,
      **ctxt_inputs,
  ):
      """
      Forward pass of the model.
  
      Due to a limitation of parlai, we have to have one single model
      in the agent. And because we want to be able to use data-parallel,
      we need to have one single forward() method.
      Therefore the operation_type can be either 'encode' or 'score'.
  
      :param ctxt_inputs:
          Dictionary of context inputs. Will include at least 'ctxt_tokens',
          containing tokenized contexts
      :param cand_tokens:
          tokenized candidates
      :param ctxt_rep:
          (bsz x num_codes x hsz)
          encoded representation of the context. If self.type == 'codes', these
          are the context codes. Otherwise, they are the outputs from the
          encoder
      :param ctxt_rep_mask:
          mask for ctxt rep
      :param cand_rep:
          encoded representation of the candidates
      """
      if len(ctxt_inputs) > 0 or cand_tokens is not None:
          return self.encode(cand_tokens=cand_tokens, **ctxt_inputs)
      elif (
          ctxt_rep is not None
          and ctxt_rep_mask is not None
          and cand_rep is not None
      ):
          return self.score(ctxt_rep, ctxt_rep_mask, cand_rep)
      raise Exception("Unsupported operation")
  
imports: from parlai.core.params import ParlaiParser
  from typing import Any, Dict, Optional, Tuple
  import torch
  from parlai.core.opt import Opt
  from parlai.core.torch_ranker_agent import TorchRankerAgent
  from parlai.core.torch_agent import Batch
  from parlai.utils.misc import recursive_getattr
  from parlai.utils.logging import logging
  from .biencoder import AddLabelFixedCandsTRA
  from .modules import BasicAttention, MultiHeadAttention, TransformerEncoder
  from .transformer import TransformerRankerAgent
label_desc: Use image node_id 9 for calling the PolyEncoderModule obj's underlying member method code with example usage: obj.forward(cand_tokens, ctxt_rep, ctxt_rep_mask, cand_rep) and returns: self, self