code: def positional_encoding(
      inputs,
      num_units=None,
      zero_pad=True,
      scale=True,
      scope="positional_encoding",
      reuse=None,
  ):
      """
      Return positinal embedding.
      """
      Shape = tf.shape(inputs)
      N = Shape[0]
      T = Shape[1]
      num_units = Shape[2]
      with tf.variable_scope(scope, reuse=reuse):
          position_ind = tf.tile(tf.expand_dims(tf.range(T), 0), [N, 1])
  
          # First part of the PE function: sin and cos argument
          #  Second part, apply the cosine to even columns and sin to odds.
          X = tf.expand_dims(tf.cast(tf.range(T), tf.float32), axis=1)
          Y = tf.expand_dims(
              tf.cast(
                  10000 ** -(2 * tf.range(num_units) / num_units),
                  tf.float32,
              ),
              axis=0,
          )
          h1 = tf.cast((tf.range(num_units) + 1) % 2, tf.float32)
          h2 = tf.cast((tf.range(num_units) % 2), tf.float32)
          position_enc = tf.multiply(X, Y)
          position_enc = tf.sin(position_enc) * tf.multiply(
              tf.ones_like(X), h1
          ) + tf.cos(position_enc) * tf.multiply(tf.ones_like(X), h2)
  
          # Convert to a tensor
          lookup_table = position_enc
  
          if zero_pad:
              lookup_table = tf.concat(
                  (tf.zeros(shape=[1, num_units]), lookup_table[1:, :]),
                  0,
              )
          outputs = tf.nn.embedding_lookup(lookup_table, position_ind)
  
          if scale:
              outputs = outputs * tf.sqrt(
                  tf.cast(num_units, tf.float32)
              )
  
          return outputs
  
file_path: nni/examples/trials/weight_sharing/ga_squad/graph_to_tf.py
imports: import tensorflow
  from rnn import XGRUCell
  from util import dropout
  from graph import LayerType
label_desc: Use image node_id 3 for calling a global function with example usage: positional_encoding(inputs, num_units, zero_pad, scale, scope, reuse) and returns: outputs