code: def get_pos_embedding(max_length, embedding_dim):
      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(max_length, dtype=torch.float).unsqueeze(
          1
      ) * emb.unsqueeze(0)
      emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1).view(
          max_length, -1
      )
      if embedding_dim % 2 == 1:
          emb = torch.cat([emb, torch.zeros(max_length, 1)], dim=1)
      return emb
  
file_path: lightseq/lightseq/training/ops/pytorch/util.py
imports: import math
  from typing import Callable
  import numpy
  import torch
  import torch.nn.functional
label_desc: Use image node_id 8 for calling a global function with example usage: get_pos_embedding(max_length, embedding_dim) and returns: emb