code: def get_sinusoid_encoding_table(
      n_position: int, d_hid: int, padding_idx=None
  ) -> "torch.FloatTensor":
      """
      sinusoid 的 embedding，其中 ``position`` 的表示中，偶数维 ``(0,2,4,...)`` 是 sin，奇数 ``(1,3,5...)`` 是 cos。
  
      :param int n_position: 一共多少个 position
      :param int d_hid: 多少维度，需要为偶数
      :param padding_idx:
      :return: 形状为 ``[n_position, d_hid]`` 的张量
      """
  
      def cal_angle(position, hid_idx):
          return position / np.power(10000, 2 * (hid_idx // 2) / d_hid)
  
      def get_posi_angle_vec(position):
          return [cal_angle(position, hid_j) for hid_j in range(d_hid)]
  
      sinusoid_table = np.array(
          [get_posi_angle_vec(pos_i) for pos_i in range(n_position)]
      )
  
      sinusoid_table[:, 0::2] = np.sin(
          sinusoid_table[:, 0::2]
      )  # dim 2i
      sinusoid_table[:, 1::2] = np.cos(
          sinusoid_table[:, 1::2]
      )  # dim 2i+1
  
      if padding_idx is not None:
          # zero vector for padding dimension
          sinusoid_table[padding_idx] = 0.0
  
      return torch.FloatTensor(sinusoid_table)
  
imports: import numpy
  from ...envs.imports import _NEED_IMPORT_TORCH
  from ...core.vocabulary import Vocabulary
label_desc: Use image node_id 3 for calling a global function with example usage: get_sinusoid_encoding_table(n_position, d_hid, padding_idx) and returns: torch, unknown, unknown