class_docstr: Sinusoidal positional encoding for non-recurrent neural networks.
  
  Implementation based on "Attention Is All You Need"
  :cite:`DBLP:journals/corr/VaswaniSPUJGKP17`
  
  Args:
     dim (int): embedding size
class_docstr_tok: ["Sinusoidal","positional","encoding","for","non-recurrent","neural","networks",".","Implementation","based","on","``","Attention","Is","All","You","Need","''",":","cite",":","`","DBLP",":","journals\/corr\/VaswaniSPUJGKP17","`","Args",":","dim","(","int",")",":","embedding","size"]
docstr: Embed inputs.
  
  Args:
      emb (FloatTensor): Sequence of word vectors
          ``(batch_size, seq_len, self.dim)``
      step (int or NoneType): If stepwise (``seq_len = 1``), use
          the encoding for this position.
docstr_tok: ["Embed","inputs",".","Args",":","emb","(","FloatTensor",")",":","Sequence","of","word","vectors","``","(","batch_size",",","seq_len",",","self.dim",")","``","step","(","int","or","NoneType",")",":","If","stepwise","(","``","seq_len","=","1","``",")",",","use","the","encoding","for","this","position","."]
code: def forward(self, emb, step=None):
      """Embed inputs.
  
      Args:
          emb (FloatTensor): Sequence of word vectors
              ``(batch_size, seq_len, self.dim)``
          step (int or NoneType): If stepwise (``seq_len = 1``), use
              the encoding for this position.
      """
      pe = self.pe.transpose(0, 1)  # (batch x len x dim)
      emb = emb * math.sqrt(self.dim)
      step = step or 0
      if pe.size(1) < step + emb.size(1):
          raise SequenceTooLongError(
              f"Sequence is {emb.size(1) + step} but PositionalEncoding is"
              f" limited to {self.pe.size(1)}. See max_len argument."
          )
      emb = emb + pe[:, step : emb.size(1) + step, :]
  
      return emb
  
imports: import math
  import warnings
  import torch
  import torch.nn
  from torch.nn.utils import skip_init
  from onmt.modules.util_class import Elementwise
  from onmt.utils.logging import logger
label_desc: Use image node_id 2 for calling the PositionalEncoding obj's underlying member method code with example usage: obj.forward(emb, step) and returns: emb