docstr: Build sinusoidal embeddings. Adapted from Fairseq.
docstr_tok: ["Build","sinusoidal","embeddings",".","Adapted","from","Fairseq","."]
code: def get_weights(self) -> Tensor:
      """Build sinusoidal embeddings. Adapted from Fairseq."""
      half_dim = self.embedding_dim // 2
      emb = math.log(10000) / (half_dim - 1)
      emb = torch.exp(torch.arange(half_dim, dtype=torch.float) * -emb)
      emb = torch.arange(
          self.num_embeddings, dtype=torch.float
      ).unsqueeze(1) * emb.unsqueeze(0)
      emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1).reshape(
          self.num_embeddings, -1
      )
      if self.embedding_dim % 2 == 1:
          # zero pad
          emb = torch.cat(
              [emb, torch.zeros(self.num_embeddings, 1)], dim=1
          )
  
      # set embeddings corresponding to padding index to 0
      if self.padding_idx is not None:
          emb[self.padding_idx, :] = 0
      return emb.unsqueeze(0).unsqueeze(0)
  
imports: import math
  from typing import Optional
  import torch
  from torch import Tensor, nn
  from torch.nn import functional
  from cvnets.layers import BaseLayer
label_desc: Use image node_id 2 for calling the SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj.get_weights() and returns: emb