class_docstr: Position attention decoder for RobustScanner.
  
  RobustScanner: `RobustScanner: Dynamically Enhancing Positional Clues for
  Robust Text Recognition <https://arxiv.org/abs/2007.07542>`_
  
  Args:
      num_classes (int): Number of output classes :math:`C`.
      rnn_layers (int): Number of RNN layers.
      dim_input (int): Dimension :math:`D_i` of input vector ``feat``.
      dim_model (int): Dimension :math:`D_m` of the model. Should also be the
          same as encoder output vector ``out_enc``.
      max_seq_len (int): Maximum output sequence length :math:`T`.
      mask (bool): Whether to mask input features according to
          ``img_meta['valid_ratio']``.
      return_feature (bool): Return feature or logits as the result.
      encode_value (bool): Whether to use the output of encoder ``out_enc``
          as `value` of attention layer. If False, the original feature
          ``feat`` will be used.
  
  Warning:
      This decoder will not predict the final class which is assumed to be
      `<PAD>`. Therefore, its output size is always :math:`C - 1`. `<PAD>`
      is also ignored by loss
      
docstr: Args:
      feat (Tensor): Tensor of shape :math:`(N, D_i, H, W)`.
      out_enc (Tensor): Encoder output of shape
          :math:`(N, D_m, H, W)`.
      valid_ratios (Tensor): valid length ratio of img
      position_index (Tensor): The position of each word.
  
  Returns:
      Tensor: A raw logit tensor of shape :math:`(N, T, C-1)` if
      ``return_feature=False``. Otherwise it would be the hidden feature
      before the prediction projection layer, whose shape is
      :math:`(N, T, D_m)`.
docstr_tok: ["Args",":","feat","(","Tensor",")",":","Tensor","of","shape",":","math",":","`","(","N",",","D_i",",","H",",","W",")","`",".","out_enc","(","Tensor",")",":","Encoder","output","of","shape",":","math",":","`","(","N",",","D_m",",","H",",","W",")","`",".","valid_ratios","(","Tensor",")",":","valid","length","ratio","of","img","position_index","(","Tensor",")",":","The","position","of","each","word",".","Returns",":","Tensor",":","A","raw","logit","tensor","of","shape",":","math",":","`","(","N",",","T",",","C-1",")","`","if","``","return_feature=False","``",".","Otherwise","it","would","be","the","hidden","feature","before","the","prediction","projection","layer",",","whose","shape","is",":","math",":","`","(","N",",","T",",","D_m",")","`","."]
code: def forward_test(self, feat, out_enc, valid_ratios, position_index):
      """
      Args:
          feat (Tensor): Tensor of shape :math:`(N, D_i, H, W)`.
          out_enc (Tensor): Encoder output of shape
              :math:`(N, D_m, H, W)`.
          valid_ratios (Tensor): valid length ratio of img
          position_index (Tensor): The position of each word.
  
      Returns:
          Tensor: A raw logit tensor of shape :math:`(N, T, C-1)` if
          ``return_feature=False``. Otherwise it would be the hidden feature
          before the prediction projection layer, whose shape is
          :math:`(N, T, D_m)`.
      """
      n, c_enc, h, w = out_enc.shape
      assert c_enc == self.dim_model
      _, c_feat, _, _ = feat.shape
      assert c_feat == self.dim_input
  
      position_out_enc = self.position_aware_module(out_enc)
  
      query = self.embedding(position_index)
      query = paddle.transpose(query, (0, 2, 1))
      key = paddle.reshape(position_out_enc, (n, c_enc, h * w))
      if self.encode_value:
          value = paddle.reshape(out_enc, (n, c_enc, h * w))
      else:
          value = paddle.reshape(feat, (n, c_feat, h * w))
  
      attn_out = self.attention_layer(
          query, key, value, h, w, valid_ratios
      )
      attn_out = paddle.transpose(
          attn_out, (0, 2, 1)
      )  # [n, len_q, dim_v]
  
      if self.return_feature:
          return attn_out
  
      return self.prediction(attn_out)
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import math
  import paddle
  from paddle import ParamAttr
  import paddle.nn
  import paddle.nn.functional
label_desc: Use image node_id 4 for calling the PositionAttentionDecoder obj's underlying member method code with example usage: obj.forward_test(feat, out_enc, valid_ratios, position_index) and returns: self, attn_out