class_docstr: Positional encoding module until v.0.5.2.
class_docstr_tok: ["Positional","encoding","module","until","v.0.5.2","."]
code: def __init__(self, d_model, dropout_rate, max_len=5000):
      import math
  
      super().__init__()
      self.dropout = torch.nn.Dropout(p=dropout_rate)
      # Compute the positional encodings once in log space.
      pe = torch.zeros(max_len, d_model)
      position = torch.arange(
          0, max_len, dtype=torch.float32
      ).unsqueeze(1)
      div_term = torch.exp(
          torch.arange(0, d_model, 2, dtype=torch.float32)
          * -(math.log(10000.0) / d_model)
      )
      pe[:, 0::2] = torch.sin(position * div_term)
      pe[:, 1::2] = torch.cos(position * div_term)
      pe = pe.unsqueeze(0)
      self.max_len = max_len
      self.xscale = math.sqrt(d_model)
      self.register_buffer("pe", pe)
  
file_path: espnet/test/test_positional_encoding.py
imports: import pytest
  import torch
  from espnet.nets.pytorch_backend.transformer.embedding import LearnableFourierPosEnc, PositionalEncoding, ScaledPositionalEncoding
label_desc: Use image node_id 1 to create a new LegacyPositionalEncoding object from inherited base classes: torch.nn with example: obj = LegacyPositionalEncoding(d_model, dropout_rate, max_len)