class_docstr: This module produces sinusoidal positional embeddings of any length.
class_docstr_tok: ["This","module","produces","sinusoidal","positional","embeddings","of","any","length","."]
docstr: 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".
docstr_tok: ["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","''","."]
code: def get_embedding(
      num_embeddings: int,
      embedding_dim: int,
      padding_idx: Optional[int] = None,
  ):
      """
      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)
      if padding_idx is not None:
          emb[padding_idx, :] = 0
  
      return emb.to(torch.get_default_dtype())
  
imports: import math
  import random
  from typing import List, Optional, Tuple, Union
  import torch
  from torch import nn
  from torch.nn import CrossEntropyLoss
  from ...activations import ACT2FN
  from ...deepspeed import is_deepspeed_zero3_enabled
  from ...modeling_outputs import BaseModelOutput, BaseModelOutputWithPastAndCrossAttentions, Seq2SeqLMOutput, Seq2SeqModelOutput
  from ...modeling_utils import PreTrainedModel
  from ...utils import add_code_sample_docstrings, add_end_docstrings, add_start_docstrings, add_start_docstrings_to_model_forward, logging, replace_return_docstrings
  from .configuration_m2m_100 import M2M100Config
label_desc: Use image node_id 3 for calling the M2M100SinusoidalPositionalEmbedding obj's underlying member method code with example usage: obj.get_embedding(num_embeddings, embedding_dim, padding_idx) and returns: emb