class_docstr: Memory Network hop outputs attention-weighted sum of memory embeddings.
  
  0) rotate the query embeddings 1) compute the dot product between the input vector
  and each memory vector 2) compute a softmax over the memory scores 3) compute the
  weighted sum of the memory embeddings using the probabilities 4) add the query
  embedding to the memory output and return the result
class_docstr_tok: ["Memory","Network","hop","outputs","attention-weighted","sum","of","memory","embeddings",".","0",")","rotate","the","query","embeddings","1",")","compute","the","dot","product","between","the","input","vector","and","each","memory","vector","2",")","compute","a","softmax","over","the","memory","scores","3",")","compute","the","weighted","sum","of","the","memory","embeddings","using","the","probabilities","4",")","add","the","query","embedding","to","the","memory","output","and","return","the","result"]
docstr: Compute MemNN Hop step.
  
  :param query_embs:
      (bsz x esz) embedding of queries
  
  :param in_mem_embs:
      bsz list of (num_mems x esz) embedding of memories for activation
  
  :param out_mem_embs:
      bsz list of (num_mems x esz) embedding of memories for outputs
  
  :param pad_mask
      (bsz x num_mems) optional mask indicating which tokens correspond to
      padding
  
  :returns:
      (bsz x esz) output state
docstr_tok: ["Compute","MemNN","Hop","step",".",":","param","query_embs",":","(","bsz","x","esz",")","embedding","of","queries",":","param","in_mem_embs",":","bsz","list","of","(","num_mems","x","esz",")","embedding","of","memories","for","activation",":","param","out_mem_embs",":","bsz","list","of","(","num_mems","x","esz",")","embedding","of","memories","for","outputs",":","param","pad_mask","(","bsz","x","num_mems",")","optional","mask","indicating","which","tokens","correspond","to","padding",":","returns",":","(","bsz","x","esz",")","output","state"]
code: def forward(self, query_embs, in_mem_embs, out_mem_embs, pad_mask):
      """
      Compute MemNN Hop step.
  
      :param query_embs:
          (bsz x esz) embedding of queries
  
      :param in_mem_embs:
          bsz list of (num_mems x esz) embedding of memories for activation
  
      :param out_mem_embs:
          bsz list of (num_mems x esz) embedding of memories for outputs
  
      :param pad_mask
          (bsz x num_mems) optional mask indicating which tokens correspond to
          padding
  
      :returns:
          (bsz x esz) output state
      """
      # rotate query embeddings
      attn = torch.bmm(query_embs.unsqueeze(1), in_mem_embs).squeeze(1)
      if pad_mask is not None:
          attn[pad_mask] = neginf(attn.dtype)
      probs = self.softmax(attn)
      memory_output = torch.bmm(
          probs.unsqueeze(1), out_mem_embs
      ).squeeze(1)
      output = memory_output + self.rotate(query_embs)
      return output
  
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 Hop obj's underlying member method code with example usage: obj.forward(query_embs, in_mem_embs, out_mem_embs, pad_mask) and returns: output