class_docstr: Relative positional encodings.
class_docstr_tok: ["Relative","positional","encodings","."]
docstr: Compute relative positional encoding.
  
  Args
      batch_size: int
          Batch size of the input
  
      max_time: int
          Sequence length of the input
  
      total_len: int
          Sequence length + Memory length
  
      clamp_len (optional): int
          Clamp all relative distances larger than clamp_len.
          None means no clamping.
  
      attn_type (optional): str
          Attention type. Supported values are `"uni"` and `"bi"`.
  
      bi_data (optional): bool
          Whether to use bidirectional data input pipeline. Usually set to
          True during pretraining and False during finetuning.
  
  :returns: A tensor of shape `[total_len + max_time, batch_size, dim]`
      (if attn_type == `"bi"`) or of shape `[total_len, batch_size, dim]`
      (if attn_type == `"uni"`) representing relative positional encoding
      of the sequence.
docstr_tok: ["Compute","relative","positional","encoding",".","Args","batch_size",":","int","Batch","size","of","the","input","max_time",":","int","Sequence","length","of","the","input","total_len",":","int","Sequence","length","+","Memory","length","clamp_len","(","optional",")",":","int","Clamp","all","relative","distances","larger","than","clamp_len",".","None","means","no","clamping",".","attn_type","(","optional",")",":","str","Attention","type",".","Supported","values","are","`","``","uni","''","`","and","`","``","bi","''","`",".","bi_data","(","optional",")",":","bool","Whether","to","use","bidirectional","data","input","pipeline",".","Usually","set","to","True","during","pretraining","and","False","during","finetuning",".",":","returns",":","A","tensor","of","shape","`","[","total_len","+","max_time",",","batch_size",",","dim","]","`","(","if","attn_type","==","`","``","bi","''","`",")","or","of","shape","`","[","total_len",",","batch_size",",","dim","]","`","(","if","attn_type","==","`","``","uni","''","`",")","representing","relative","positional","encoding","of","the","sequence","."]
code: def _build(
      self,
      batch_size,
      max_time,
      total_len,
      clamp_len=None,
      attn_type="bi",
      bi_data=True,
  ):
      r"""Compute relative positional encoding.
  
      Args
          batch_size: int
              Batch size of the input
  
          max_time: int
              Sequence length of the input
  
          total_len: int
              Sequence length + Memory length
  
          clamp_len (optional): int
              Clamp all relative distances larger than clamp_len.
              None means no clamping.
  
          attn_type (optional): str
              Attention type. Supported values are `"uni"` and `"bi"`.
  
          bi_data (optional): bool
              Whether to use bidirectional data input pipeline. Usually set to
              True during pretraining and False during finetuning.
  
      :returns: A tensor of shape `[total_len + max_time, batch_size, dim]`
          (if attn_type == `"bi"`) or of shape `[total_len, batch_size, dim]`
          (if attn_type == `"uni"`) representing relative positional encoding
          of the sequence.
      """
      if attn_type == "bi":
          start, end = total_len, -max_time
      elif attn_type == "uni":
          start, end = total_len, -1
      else:
          raise ValueError("Unknown `attn_type` {}".format(attn_type))
  
      if bi_data:
          if batch_size % 2 != 0:
              raise ValueError("`batch_size` must be an even number")
          fwd_pos_embed = self._create_positional_embedding(
              start, end, -1, batch_size // 2, clamp_len
          )
          bwd_pos_embed = self._create_positional_embedding(
              -start, -end, 1, batch_size // 2, clamp_len
          )
          pos_embed = tf.concat([fwd_pos_embed, bwd_pos_embed], axis=1)
      else:
          pos_embed = self._create_positional_embedding(
              start, end, -1, batch_size, clamp_len
          )
      return pos_embed
  
imports: import tensorflow
  from texar.tf.core import layers
  from texar.tf.module_base import ModuleBase
  from texar.tf.utils.mode import is_train_mode
label_desc: Use image node_id 4 for calling the RelativePositionalEncoding obj's underlying member method code with example usage: obj._build(batch_size, max_time, total_len, clamp_len, attn_type, bi_data) and returns: pos_embed