class_docstr: Fixed positional encoding with sine and cosine functions.
docstr: Sinusoid position encoding table.
docstr_tok: ["Sinusoid","position","encoding","table","."]
code: def _get_sinusoid_encoding_table(self, n_position, d_hid):
      """Sinusoid position encoding table."""
      denominator = torch.Tensor(
          [
              1.0 / np.power(10000, 2 * (hid_j // 2) / d_hid)
              for hid_j in range(d_hid)
          ]
      )
      denominator = denominator.view(1, -1)
      pos_tensor = torch.arange(n_position).unsqueeze(-1).float()
      sinusoid_table = pos_tensor * denominator
      sinusoid_table[:, 0::2] = torch.sin(sinusoid_table[:, 0::2])
      sinusoid_table[:, 1::2] = torch.cos(sinusoid_table[:, 1::2])
  
      return sinusoid_table.unsqueeze(0)
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from mmocr.registry import MODELS
label_desc: Use image node_id 2 for calling the PositionalEncoding obj's underlying member method code with example usage: obj._get_sinusoid_encoding_table(n_position, d_hid) and returns: sinusoid_table