class_docstr: Positional encoding.
  
  Args:
      d_model (int): Embedding dimension.
      dropout_rate (float): Dropout rate.
      max_len (int): Maximum input length.
      reverse (bool): Whether to reverse the input position. Only for
      the class LegacyRelPositionalEncoding. We remove it in the current
      class RelPositionalEncoding.
class_docstr_tok: ["Positional","encoding",".","Args",":","d_model","(","int",")",":","Embedding","dimension",".","dropout_rate","(","float",")",":","Dropout","rate",".","max_len","(","int",")",":","Maximum","input","length",".","reverse","(","bool",")",":","Whether","to","reverse","the","input","position",".","Only","for","the","class","LegacyRelPositionalEncoding",".","We","remove","it","in","the","current","class","RelPositionalEncoding","."]
docstr: Construct an PositionalEncoding object.
docstr_tok: ["Construct","an","PositionalEncoding","object","."]
code: def __init__(
      self, d_model, dropout_rate, max_len=5000, reverse=False
  ):
      """Construct an PositionalEncoding object."""
      super(PositionalEncoding, self).__init__()
      self.d_model = d_model
      self.reverse = reverse
      self.xscale = math.sqrt(self.d_model)
      self.dropout = torch.nn.Dropout(p=dropout_rate)
      self.pe = None
      self.extend_pe(torch.tensor(0.0).expand(1, max_len))
      self._register_load_state_dict_pre_hook(_pre_hook)
  
imports: import math
  import torch
label_desc: Use image node_id 1 to create a new PositionalEncoding object from inherited base classes: torch.nn with example: obj = PositionalEncoding(d_model, dropout_rate, max_len, reverse)