class_docstr: Uses sine & cosine to represent position
class_docstr_tok: ["Uses","sine","&","cosine","to","represent","position"]
code: def forward(self, x):
      if max(x) >= self.pe.shape[0]:
          # try to drop the reference first before creating a new encoding
          # the goal being to save memory if we are close to the memory limit
          device = self.pe.device
          shape = self.pe.shape[1]
          self.register_buffer("pe", None)
          # TODO: this may result in very poor performance
          # in the event of a model that increases size one at a time
          self.register_buffer(
              "pe",
              self.build_position(shape, max(x) + 1, device=device),
          )
      return self.pe[x]
  
file_path: stanza/stanza/models/constituency/positional_encoding.py
imports: import math
  import torch
  from torch import nn
label_desc: Use image node_id 3 for calling the SinusoidalEncoding obj's underlying member method code with example usage: obj.forward(x) and returns: self