class_docstr: Implements bare positional encoding.
  
  Positional encoding includes a kind of dropout, if the layer is created in
  ``'train'`` mode with a nonzero ``dropout`` value. For such a layer, on each
  forward pass a subset of sequence positions selected at random will *not*
  receive positional marking.
class_docstr_tok: ["Implements","bare","positional","encoding",".","Positional","encoding","includes","a","kind","of","dropout",",","if","the","layer","is","created","in","``","'train","'","``","mode","with","a","nonzero","``","dropout","``","value",".","For","such","a","layer",",","on","each","forward","pass","a","subset","of","sequence","positions","selected","at","random","will","*","not","*","receive","positional","marking","."]
docstr: Randomly initializes the positional encoding vectors.
  
  Args:
    input_signature: :py:class:`ShapeDtype` instance characterizing the input
        this layer should compute on.
code: def init_weights_and_state(self, input_signature):
      """Randomly initializes the positional encoding vectors.
  
      Args:
        input_signature: :py:class:`ShapeDtype` instance characterizing the input
            this layer should compute on.
      """
      d_feature = input_signature.shape[-1]
      if self._d_feature is not None:
          d_feature = self._d_feature
      pe = np.zeros((self._max_len, d_feature), dtype=np.float32)
      position = np.arange(0, self._max_len)[:, np.newaxis]
      div_term = np.exp(
          np.arange(0, d_feature, 2) * -(np.log(10000.0) / d_feature)
      )
      pe[:, 0::2] = np.sin(position * div_term)
      pe[:, 1::2] = np.cos(
          position * div_term
      )  # [self._max_len, d_feature]
      if self._use_bfloat16:
          pe = pe.astype(jnp.bfloat16)
      w = jnp.array(pe)  # Trainable parameters, initialized above.
      if self._d_feature is not None:
          ff = init.GlorotUniformInitializer()(
              (d_feature, input_signature.shape[-1]), self.rng
          )
          self.weights = w, ff
      else:
          self.weights = w
      if self._mode == "predict":
          self.state = jnp.zeros((), dtype=jnp.int32)
  
imports: import numpy
  from trax import fastmath
  from trax.fastmath import numpy
  from trax.layers import base
  from trax.layers import combinators
  from trax.layers import convolution
  from trax.layers import core
  from trax.layers import initializers
  from trax.layers.assert_shape import assert_shape
  from trax.layers.base import Fn
  from trax.layers.research import sparsity
label_desc: Use image node_id 3 for calling the PositionalEncoding obj's underlying member method code with example usage: obj.init_weights_and_state(input_signature) without return types