class_docstr: Uses sine & cosine to represent position.  Adds the position to the given matrix
  
  Default behavior is batch_first
class_docstr_tok: ["Uses","sine","&","cosine","to","represent","position",".","Adds","the","position","to","the","given","matrix","Default","behavior","is","batch_first"]
docstr: Adds the positional encoding to the input tensor
  
  The tensor is expected to be of the shape B, N, D
  Properly masking the output tensor is up to the caller
docstr_tok: ["Adds","the","positional","encoding","to","the","input","tensor","The","tensor","is","expected","to","be","of","the","shape","B",",","N",",","D","Properly","masking","the","output","tensor","is","up","to","the","caller"]
code: def forward(self, x, scale=1.0):
      """
      Adds the positional encoding to the input tensor
  
      The tensor is expected to be of the shape B, N, D
      Properly masking the output tensor is up to the caller
      """
      if len(x.shape) == 3:
          timing = self.encoding(
              torch.arange(x.shape[1], device=x.device)
          )
          timing = timing.expand(x.shape[0], -1, -1)
      elif len(x.shape) == 2:
          timing = self.encoding(
              torch.arange(x.shape[0], device=x.device)
          )
      return x + timing * scale
  
file_path: stanza/stanza/models/constituency/positional_encoding.py
imports: import math
  import torch
  from torch import nn
label_desc: Use image node_id 2 for calling the AddSinusoidalEncoding obj's underlying member method code with example usage: obj.forward(x, scale) and returns: unknown