class_docstr: Relative positional encoding module (new implementation).
  
  Details can be found in https://github.com/espnet/espnet/pull/2816.
  
  See : Appendix B in https://arxiv.org/abs/1901.02860
  
  Args:
      d_model (int): Embedding dimension.
      dropout_rate (float): Dropout rate.
      max_len (int): Maximum input length.
class_docstr_tok: ["Relative","positional","encoding","module","(","new","implementation",")",".","Details","can","be","found","in","https",":","\/\/github.com\/espnet\/espnet\/pull\/2816",".","See",":","Appendix","B","in","https",":","\/\/arxiv.org\/abs\/1901.02860","Args",":","d_model","(","int",")",":","Embedding","dimension",".","dropout_rate","(","float",")",":","Dropout","rate",".","max_len","(","int",")",":","Maximum","input","length","."]
docstr: Add positional encoding.
  
  Args:
      x (torch.Tensor): Input tensor (batch, time, `*`).
  
  Returns:
      torch.Tensor: Encoded tensor (batch, time, `*`).
docstr_tok: ["Add","positional","encoding",".","Args",":","x","(","torch.Tensor",")",":","Input","tensor","(","batch",",","time",",","`","*","`",")",".","Returns",":","torch.Tensor",":","Encoded","tensor","(","batch",",","time",",","`","*","`",")","."]
code: def forward(self, x: torch.Tensor):
      """Add positional encoding.
  
      Args:
          x (torch.Tensor): Input tensor (batch, time, `*`).
  
      Returns:
          torch.Tensor: Encoded tensor (batch, time, `*`).
  
      """
      self.extend_pe(x)
      x = x * self.xscale
      pos_emb = self.pe[
          :,
          self.pe.size(1) // 2
          - x.size(1)
          + 1 : self.pe.size(1) // 2
          + x.size(1),
      ]
      return self.dropout(x), self.dropout(pos_emb)
  
imports: import math
  import torch
label_desc: Use image node_id 3 for calling the RelPositionalEncoding obj's underlying member method code with example usage: obj.forward(x) and returns: self,  self