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","."]
docstr: Build matrix of position encoding coeffiencents.
  
  See https://papers.nips.cc/paper/5846-end-to-end-memory-networks,
  section 4.1 Model Details: Sentence Representation.
  
  :param J:
      number of words in the sequence
  
  :param d:
      dimension of the embedding
  
  :returns:
      Position Encoding matrix
docstr_tok: ["Build","matrix","of","position","encoding","coeffiencents",".","See","https",":","\/\/papers.nips.cc\/paper\/5846-end-to-end-memory-networks",",","section","4.1","Model","Details",":","Sentence","Representation",".",":","param","J",":","number","of","words","in","the","sequence",":","param","d",":","dimension","of","the","embedding",":","returns",":","Position","Encoding","matrix"]
code: def position_matrix(J, d, use_cuda):
      """
      Build matrix of position encoding coeffiencents.
  
      See https://papers.nips.cc/paper/5846-end-to-end-memory-networks,
      section 4.1 Model Details: Sentence Representation.
  
      :param J:
          number of words in the sequence
  
      :param d:
          dimension of the embedding
  
      :returns:
          Position Encoding matrix
      """
      m = torch.Tensor(J, d)
      for k in range(1, d + 1):
          for j in range(1, J + 1):
              m[j - 1, k - 1] = (1 - j / J) - (k / d) * (1 - 2 * j / J)
      if use_cuda:
          m = m.cuda()
      return m
  
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 4 for calling the Embed obj's underlying member method code with example usage: obj.position_matrix(J, d, use_cuda) and returns: m