parameters: (self, d_model, recep_field, scope_name_prefix)
return_statement: return pos_emb
docstring: create relative positional encoding.
docstring_summary: create relative positional encoding.
docstring_tokens: create relative positional encoding .
function: def relative_positional_encoding(self, d_model, recep_field, scope_name_prefix):
          """create relative positional encoding."""
          time_len = self.params['max_sequence_length']
          freq_seq = np.arange(0, d_model, 2.0, dtype=np.float32)
          inv_freq = 1 / (10000 ** (freq_seq / d_model))
  
          fwd_pos_seq = np.arange(time_len, -1, -1.0, dtype=np.float32)
          fwd_pos_seq = np.clip(fwd_pos_seq, -recep_field, recep_field)
          sinusoid_inp = np.matmul(np.expand_dims(fwd_pos_seq, 1), np.expand_dims(inv_freq, 0))
          pos_emb = np.concatenate([np.sin(sinusoid_inp), np.cos(sinusoid_inp)], axis=-1)
          pos_emb = np.tile(pos_emb, (1, 1))
          pos_emb = self.add_weight(scope_name_prefix+"_pos_dict", weight=pos_emb, data_type="FLOAT32")
          return pos_emb
function_tokens: def relative_positional_encoding ( self , d_model , recep_field , scope_name_prefix ) : time_len = self . params [ 'max_sequence_length' ] freq_seq = np . arange ( 0 , d_model , 2.0 , dtype = np . float32 ) inv_freq = 1 / ( 10000 ** ( freq_seq / d_model ) ) fwd_pos_seq = np . arange ( time_len , - 1 , - 1.0 , dtype = np . float32 ) fwd_pos_seq = np . clip ( fwd_pos_seq , - recep_field , recep_field ) sinusoid_inp = np . matmul ( np . expand_dims ( fwd_pos_seq , 1 ) , np . expand_dims ( inv_freq , 0 ) ) pos_emb = np . concatenate ( [ np . sin ( sinusoid_inp ) , np . cos ( sinusoid_inp ) ] , axis = - 1 ) pos_emb = np . tile ( pos_emb , ( 1 , 1 ) ) pos_emb = self . add_weight ( scope_name_prefix + "_pos_dict" , weight = pos_emb , data_type = "FLOAT32" ) return pos_emb