class_docstr: Implements the sin-cos positional encoding.
class_docstr_tok: ["Implements","the","sin-cos","positional","encoding","."]
docstr: Creates a SinCosPositionalEncoding instance.
  
  Args:
    add_offset: Maximumnumber to add to positions during training.
    dropout: Probability of *not* adding positional encoding to a sequence
        position.
    dropout_broadcast_dims: Axes along which dropout mask values are
        broadcast rather than individually set at random.
    start_from_zero_one_in: how often to start from 0 during training,
        every one in that many times (e.g., if 4, then it's 25% of the time).
    mode: One of `'train'`, `'eval'`, or `'predict'`.
docstr_tok: ["Creates","a","SinCosPositionalEncoding","instance",".","Args",":","add_offset",":","Maximumnumber","to","add","to","positions","during","training",".","dropout",":","Probability","of","*","not","*","adding","positional","encoding","to","a","sequence","position",".","dropout_broadcast_dims",":","Axes","along","which","dropout","mask","values","are","broadcast","rather","than","individually","set","at","random",".","start_from_zero_one_in",":","how","often","to","start","from","0","during","training",",","every","one","in","that","many","times","(","e.g.",",","if","4",",","then","it","'s","25","%","of","the","time",")",".","mode",":","One","of","`","'train","'","`",",","`","'eval","'","`",",","or","`","'predict","'","`","."]
code: def __init__(
      self,
      add_offset=2048,
      dropout=0.0,
      dropout_broadcast_dims=(-2,),
      start_from_zero_one_in=2,
      mode="train",
  ):
      """Creates a SinCosPositionalEncoding instance.
  
      Args:
        add_offset: Maximumnumber to add to positions during training.
        dropout: Probability of *not* adding positional encoding to a sequence
            position.
        dropout_broadcast_dims: Axes along which dropout mask values are
            broadcast rather than individually set at random.
        start_from_zero_one_in: how often to start from 0 during training,
            every one in that many times (e.g., if 4, then it's 25% of the time).
        mode: One of `'train'`, `'eval'`, or `'predict'`.
      """
      super().__init__()
      self._add_offset = add_offset
      if dropout >= 1.0:
          raise ValueError("Dropout rates must be lower than 1.")
      if mode == "train":
          self._dropout = dropout
      else:
          self._dropout = 0.0
      self._dropout_broadcast_dims = dropout_broadcast_dims
      self._start_from_zero_one_in = start_from_zero_one_in
      self._mode = mode
  
imports: import logging
  import jax
  import jax.extend
  import numpy
  import trax
  from trax import fastmath
  from trax.fastmath import numpy
  from trax.layers import base
  from trax.layers import initializers
label_desc: Use image node_id 1 to create a new SinCosPositionalEncoding object from inherited base classes: layer_base with example: obj = SinCosPositionalEncoding(add_offset, dropout, dropout_broadcast_dims, start_from_zero_one_in, mode)