class_docstr: Memory Network module.
class_docstr_tok: ["Memory","Network","module","."]
docstr: One forward step.
  
  :param xs:
      (bsz x seqlen) LongTensor queries to the model
  
  :param mems:
      (bsz x num_mems x seqlen) LongTensor memories
  
  :param cands:
      (num_cands x seqlen) or (bsz x num_cands x seqlen)
      LongTensor with candidates to rank
  :param pad_mask:
      (bsz x num_mems) optional mask indicating which tokens
      correspond to padding
  
  :returns:
      scores contains the model's predicted scores.
      if cand_params is None, the candidates are the vocabulary;
      otherwise, these scores are over the candidates provided.
      (bsz x num_cands)
docstr_tok: ["One","forward","step",".",":","param","xs",":","(","bsz","x","seqlen",")","LongTensor","queries","to","the","model",":","param","mems",":","(","bsz","x","num_mems","x","seqlen",")","LongTensor","memories",":","param","cands",":","(","num_cands","x","seqlen",")","or","(","bsz","x","num_cands","x","seqlen",")","LongTensor","with","candidates","to","rank",":","param","pad_mask",":","(","bsz","x","num_mems",")","optional","mask","indicating","which","tokens","correspond","to","padding",":","returns",":","scores","contains","the","model","'s","predicted","scores",".","if","cand_params","is","None",",","the","candidates","are","the","vocabulary",";","otherwise",",","these","scores","are","over","the","candidates","provided",".","(","bsz","x","num_cands",")"]
code: def forward(self, xs, mems, cands=None, pad_mask=None):
      """
      One forward step.
  
      :param xs:
          (bsz x seqlen) LongTensor queries to the model
  
      :param mems:
          (bsz x num_mems x seqlen) LongTensor memories
  
      :param cands:
          (num_cands x seqlen) or (bsz x num_cands x seqlen)
          LongTensor with candidates to rank
      :param pad_mask:
          (bsz x num_mems) optional mask indicating which tokens
          correspond to padding
  
      :returns:
          scores contains the model's predicted scores.
          if cand_params is None, the candidates are the vocabulary;
          otherwise, these scores are over the candidates provided.
          (bsz x num_cands)
      """
      state = self.query_lt(xs)
      if mems is not None:
          # no memories available, `nomemnn` mode just uses query/ans embs
          in_memory_embs = self.in_memory_lt(mems).transpose(1, 2)
          out_memory_embs = self.out_memory_lt(mems)
  
          for _ in range(self.hops):
              state = self.memory_hop(
                  state, in_memory_embs, out_memory_embs, pad_mask
              )
  
      if cands is not None:
          # embed candidates
          cand_embs = self.answer_embedder(cands)
      else:
          # rank all possible tokens
          cand_embs = self.answer_embedder.weight
  
      return state, cand_embs
  
file_path: ParlAI/parlai/agents/memnn/modules.py
imports: import torch
  import torch.nn
  from parlai.utils.torch import neginf
  from functools import lru_cache
label_desc: Use image node_id 2 for calling the MemNN obj's underlying member method code with example usage: obj.forward(xs, mems, cands, pad_mask) and returns: state,  cand_embs