class_docstr: Multi-Head Attention layer of Transformer-XL with support of relative positional encoding.
  Paper: https://arxiv.org/abs/1901.02860
  Args:
      n_head (int): number of heads
      n_feat (int): size of the features
      dropout_rate (float): dropout rate
class_docstr_tok: ["Multi-Head","Attention","layer","of","Transformer-XL","with","support","of","relative","positional","encoding",".","Paper",":","https",":","\/\/arxiv.org\/abs\/1901.02860","Args",":","n_head","(","int",")",":","number","of","heads","n_feat","(","int",")",":","size","of","the","features","dropout_rate","(","float",")",":","dropout","rate"]
docstr: Construct an RelPositionMultiHeadedAttention object.
docstr_tok: ["Construct","an","RelPositionMultiHeadedAttention","object","."]
code: def __init__(
      self,
      n_head,
      n_feat,
      dropout_rate,
      pos_bias_u,
      pos_bias_v,
      max_cache_len=0,
  ):
      """Construct an RelPositionMultiHeadedAttention object."""
      super().__init__(
          n_head=n_head,
          n_feat=n_feat,
          dropout_rate=dropout_rate,
          max_cache_len=max_cache_len,
      )
      # linear transformation for positional encoding
      self.linear_pos = nn.Linear(n_feat, n_feat, bias=False)
      # these two learnable biases are used in matrix c and matrix d
      # as described in https://arxiv.org/abs/1901.02860 Section 3.3
      if pos_bias_u is None or pos_bias_v is None:
          self.pos_bias_u = nn.Parameter(
              torch.FloatTensor(self.h, self.d_k)
          )
          self.pos_bias_v = nn.Parameter(
              torch.FloatTensor(self.h, self.d_k)
          )
          # nn.init.normal_(self.pos_bias_u, 0.0, 0.02)
          # nn.init.normal_(self.pos_bias_v, 0.0, 0.02)
          nn.init.zeros_(self.pos_bias_u)
          nn.init.zeros_(self.pos_bias_v)
      else:
          self.pos_bias_u = pos_bias_u
          self.pos_bias_v = pos_bias_v
  
imports: import math
  from functools import lru_cache
  from typing import List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from nemo.utils import avoid_float16_autocast_context
label_desc: Use image node_id 1 to create a new RelPositionMultiHeadAttention object from inherited base classes: MultiHeadAttention with example: obj = RelPositionMultiHeadAttention(n_head, n_feat, dropout_rate, pos_bias_u, pos_bias_v, max_cache_len)