code: def get_positional_encoding(d_model: int, max_len: int = 5000):
      # Empty encodings vectors
      encodings = torch.zeros(max_len, d_model)
      # Position indexes
      position = torch.arange(
          0, max_len, dtype=torch.float32
      ).unsqueeze(1)
      # $2 * i$
      two_i = torch.arange(0, d_model, 2, dtype=torch.float32)
      # $10000^{\frac{2i}{d_{model}}}$
      div_term = torch.exp(two_i * -(math.log(10000.0) / d_model))
      # $PE_{p,2i} = sin\Bigg(\frac{p}{10000^{\frac{2i}{d_{model}}}}\Bigg)$
      encodings[:, 0::2] = torch.sin(position * div_term)
      # $PE_{p,2i + 1} = cos\Bigg(\frac{p}{10000^{\frac{2i}{d_{model}}}}\Bigg)$
      encodings[:, 1::2] = torch.cos(position * div_term)
  
      # Add batch dimension
      encodings = encodings.unsqueeze(1).requires_grad_(False)
  
      return encodings
  
file_path: annotated_deep_learning_paper_implementations/labml_nn/transformers/positional_encoding.py
imports: import math
  import numpy
  import torch
  import torch.nn
label_desc: Use image node_id 1 for calling a global function with example usage: get_positional_encoding(d_model, max_len) and returns: encodings