class_docstr: Model which takes context, memories, candidates and encodes them.
class_docstr_tok: ["Model","which","takes","context",",","memories",",","candidates","and","encodes","them","."]
docstr: Forward pass.
  
  :param LongTensor[batch,seqlen] xs: input tokens IDs
  :param LongTensor[batch,num_mems,seqlen] mems: memory token IDs
  :param LongTensor[batch,num_cands,seqlen] cands: candidate token IDs
  :param LongTensor[batch,seqlen] context_segments: segment IDs for xs,
      used if n_segments is > 0 for the context encoder
docstr_tok: ["Forward","pass",".",":","param","LongTensor","[","batch",",","seqlen","]","xs",":","input","tokens","IDs",":","param","LongTensor","[","batch",",","num_mems",",","seqlen","]","mems",":","memory","token","IDs",":","param","LongTensor","[","batch",",","num_cands",",","seqlen","]","cands",":","candidate","token","IDs",":","param","LongTensor","[","batch",",","seqlen","]","context_segments",":","segment","IDs","for","xs",",","used","if","n_segments","is",">","0","for","the","context","encoder"]
code: def forward(
      self,
      xs: torch.LongTensor,
      mems: torch.LongTensor,
      cands: torch.LongTensor,
      context_segments: Optional[torch.LongTensor] = None,
  ) -> Tuple[torch.LongTensor, torch.LongTensor]:
      """
      Forward pass.
  
      :param LongTensor[batch,seqlen] xs: input tokens IDs
      :param LongTensor[batch,num_mems,seqlen] mems: memory token IDs
      :param LongTensor[batch,num_cands,seqlen] cands: candidate token IDs
      :param LongTensor[batch,seqlen] context_segments: segment IDs for xs,
          used if n_segments is > 0 for the context encoder
      """
      # encode the context and memories together
      weights, context_h = self.encode_context_memory(
          xs, mems, context_segments=context_segments
      )
      # encode the candidates
      cands_h = self.encode_cand(cands)
  
      # possibly normalize the context and candidate representations
      if self.opt["normalize_sent_emb"]:
          context_h = context_h / context_h.norm(2, dim=1, keepdim=True)
          cands_h = cands_h / cands_h.norm(2, dim=1, keepdim=True)
  
      return context_h, cands_h
  
file_path: ParlAI/parlai/agents/transformer/modules/mem_net.py
imports: import torch
  import torch.nn
  from typing import Optional, Tuple
  from parlai.agents.transformer.modules import create_embeddings, BasicAttention, TransformerEncoder, TransformerResponseWrapper
  from parlai.core.opt import Opt
  from parlai.core.torch_agent import DictionaryAgent
label_desc: Use image node_id 7 for calling the TransformerMemNetModel obj's underlying member method code with example usage: obj.forward(xs, mems, cands, context_segments) and returns: context_h,  cands_h