class_docstr: Embed sequences for MemNN model.
  
  Applies Position Encoding if enabled and currently applies BOW sum.
class_docstr_tok: ["Embed","sequences","for","MemNN","model",".","Applies","Position","Encoding","if","enabled","and","currently","applies","BOW","sum","."]
code: def _reduce(self, embs, input):
      # last dimension is embedding, do operation over dim before that
      if self.reduction == "sum":
          return embs.sum(-2)
      elif self.reduction == "mean":
          # this is more fair than mean(-2) since mean includes null tokens
          sum = embs.sum(-2)
          lens = (
              input.ne(self.padding_idx)
              .sum(-1)
              .unsqueeze(-1)
              .float()
              .clamp_(min=1)
          )
          return sum / lens
      else:
          raise RuntimeError(
              "reduction method {} not supported".format(self.reduction)
          )
  
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 Embed obj's underlying member method code with example usage: obj._reduce(embs, input) and returns: embs, unknown