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: Reset the positional encodings.
docstr_tok: ["Reset","the","positional","encodings","."]
code: def extend_pe(self, x):
      """Reset the positional encodings."""
      position_v = (
          torch.arange(0, x.size(1), dtype=torch.float32)
          .unsqueeze(1)
          .to(x)
      )
  
      cosine = torch.cos(torch.matmul(position_v, self.w_r))
      sine = torch.sin(torch.matmul(position_v, self.w_r))
      pos_enc = torch.cat((cosine, sine), -1)
      pos_enc /= math.sqrt(self.d_model)
  
      if self.hidden_dim is None:
          return pos_enc.unsqueeze(0)
      else:
          return self.mlp(pos_enc.unsqueeze(0))
  
imports: import math
  import torch
label_desc: Use image node_id 3 for calling the LearnableFourierPosEnc obj's underlying member method code with example usage: obj.extend_pe(x) and returns: pos_enc, self