code: def get_sinusoidal_embedding(
      num_embeddings: int, embedding_dim: int, padding_idx: int
  ):
      """Build sinusoidal embeddings.
  
      This matches the implementation in tensor2tensor, but differs slightly
      from the description in Section 3.5 of "Attention Is All You Need".
      """
      half_dim = embedding_dim // 2
      emb = math.log(10000) / (half_dim - 1)
      emb = torch.exp(torch.arange(half_dim, dtype=torch.float) * -emb)
      emb = torch.arange(num_embeddings, dtype=torch.float).unsqueeze(
          1
      ) * emb.unsqueeze(0)
      emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1).view(
          num_embeddings, -1
      )
      if embedding_dim % 2 == 1:
          # zero pad
          emb = torch.cat([emb, torch.zeros(num_embeddings, 1)], dim=1)
  
      # Positions < padding_idx are ignored and won't be used.
      emb[padding_idx, :] = 0
      return emb
  
imports: import math
  from enum import Enum
  from typing import Dict, Optional
  import torch
  import torch.nn
  import torch.nn.functional
  from pytext.models.representations.transformer import PositionalEmbedding
  from pytext.models.seq_models.base import PlaceholderIdentity
  from torch import Tensor
  from .utils import make_positions
label_desc: Use image node_id 1 for calling a global function with example usage: get_sinusoidal_embedding(num_embeddings, embedding_dim, padding_idx) and returns: emb