class_docstr: Learnable Fourier Features for Positional Encoding.
  
  See https://arxiv.org/pdf/2106.02795.pdf
  
  Args:
      d_model (int): Embedding dimension.
      dropout_rate (float): Dropout rate.
      max_len (int): Maximum input length.
      gamma (float): init parameter for the positional kernel variance
          see https://arxiv.org/pdf/2106.02795.pdf.
      apply_scaling (bool): Whether to scale the input before adding the pos encoding.
      hidden_dim (int): if not None, we modulate the pos encodings with
          an MLP whose hidden layer has hidden_dim neurons.
class_docstr_tok: ["Learnable","Fourier","Features","for","Positional","Encoding",".","See","https",":","\/\/arxiv.org\/pdf\/2106.02795.pdf","Args",":","d_model","(","int",")",":","Embedding","dimension",".","dropout_rate","(","float",")",":","Dropout","rate",".","max_len","(","int",")",":","Maximum","input","length",".","gamma","(","float",")",":","init","parameter","for","the","positional","kernel","variance","see","https",":","\/\/arxiv.org\/pdf\/2106.02795.pdf",".","apply_scaling","(","bool",")",":","Whether","to","scale","the","input","before","adding","the","pos","encoding",".","hidden_dim","(","int",")",":","if","not","None",",","we","modulate","the","pos","encodings","with","an","MLP","whose","hidden","layer","has","hidden_dim","neurons","."]
docstr: Initialize class.
docstr_tok: ["Initialize","class","."]
code: def __init__(
      self,
      d_model,
      dropout_rate=0.0,
      max_len=5000,
      gamma=1.0,
      apply_scaling=False,
      hidden_dim=None,
  ):
      """Initialize class."""
      super(LearnableFourierPosEnc, self).__init__()
  
      self.d_model = d_model
  
      if apply_scaling:
          self.xscale = math.sqrt(self.d_model)
      else:
          self.xscale = 1.0
  
      self.dropout = torch.nn.Dropout(dropout_rate)
      self.max_len = max_len
  
      self.gamma = gamma
      if self.gamma is None:
          self.gamma = self.d_model // 2
  
      assert (
          d_model % 2 == 0
      ), "d_model should be divisible by two in order to use this layer."
      self.w_r = torch.nn.Parameter(torch.empty(1, d_model // 2))
      self._reset()  # init the weights
  
      self.hidden_dim = hidden_dim
      if self.hidden_dim is not None:
          self.mlp = torch.nn.Sequential(
              torch.nn.Linear(d_model, hidden_dim),
              torch.nn.GELU(),
              torch.nn.Linear(hidden_dim, d_model),
          )
  
imports: import math
  import torch
label_desc: Use image node_id 1 to create a new LearnableFourierPosEnc object from inherited base classes: torch.nn with example: obj = LearnableFourierPosEnc(d_model, dropout_rate, max_len, gamma, apply_scaling, hidden_dim)