class_docstr: Compute positional encoding
class_docstr_tok: ["Compute","positional","encoding"]
code: def __init__(
      self, d_model: int, dropout: float = 0.1, max_len: int = 5000
  ) -> None:
      super(PositionalEncoding, self).__init__()
      self.dropout = layers.Dropout(rate=dropout)
  
      # Compute the positional encodings once in log space.
      pe = tf.Variable(tf.zeros((max_len, d_model)))
      position = tf.cast(
          tf.expand_dims(
              tf.experimental.numpy.arange(start=0, stop=max_len),
              axis=1,
          ),
          dtype=tf.float32,
      )
      div_term = tf.math.exp(
          tf.cast(
              tf.experimental.numpy.arange(
                  start=0, stop=d_model, step=2
              ),
              dtype=tf.float32,
          )
          * -(math.log(10000.0) / d_model)
      )
      pe = pe.numpy()
      pe[:, 0::2] = tf.math.sin(position * div_term)
      pe[:, 1::2] = tf.math.cos(position * div_term)
      self.pe = tf.expand_dims(tf.convert_to_tensor(pe), axis=0)
  
imports: import math
  from typing import Any, Callable, Optional, Tuple
  import tensorflow
  from tensorflow.keras import layers
  from doctr.utils.repr import NestedObject
label_desc: Use image node_id 1 to create a new PositionalEncoding object from inherited base classes: layers, NestedObject with example: obj = PositionalEncoding(d_model, dropout, max_len)