class_docstr: Position attention decoder for RobustScanner.
  
  RobustScanner: `RobustScanner: Dynamically Enhancing Positional Clues for
  Robust Text Recognition <https://arxiv.org/abs/2007.07542>`_
  
  Args:
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`.
      module_loss (dict, optional): Config to build module_loss. Defaults
          to None.
      postprocessor (dict, optional): Config to build postprocessor.
          Defaults to None.
      rnn_layers (int): Number of RNN layers. Defaults to 2.
      dim_input (int): Dimension :math:`D_i` of input vector ``feat``.
          Defaults to 512.
      dim_model (int): Dimension :math:`D_m` of the model. Should also be the
          same as encoder output vector ``out_enc``. Defaults to 128.
      max_seq_len (int): Maximum output sequence length :math:`T`. Defaults
          to 40.
      mask (bool): Whether to mask input features according to
          ``img_meta['valid_ratio']``. Defaults to True.
      return_feature (bool): Return feature or logits as the result. Defaults
          to True.
      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. Defaults to False.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["Position","attention","decoder","for","RobustScanner",".","RobustScanner",":","`","RobustScanner",":","Dynamically","Enhancing","Positional","Clues","for","Robust","Text","Recognition","<","https",":","\/\/arxiv.org\/abs\/2007.07542",">","`","_","Args",":","dictionary","(","dict","or",":","obj",":","`","Dictionary","`",")",":","The","config","for","`","Dictionary","`","or","the","instance","of","`","Dictionary","`",".","module_loss","(","dict",",","optional",")",":","Config","to","build","module_loss",".","Defaults","to","None",".","postprocessor","(","dict",",","optional",")",":","Config","to","build","postprocessor",".","Defaults","to","None",".","rnn_layers","(","int",")",":","Number","of","RNN","layers",".","Defaults","to","2.","dim_input","(","int",")",":","Dimension",":","math",":","`","D_i","`","of","input","vector","``","feat","``",".","Defaults","to","512.","dim_model","(","int",")",":","Dimension",":","math",":","`","D_m","`","of","the","model",".","Should","also","be","the","same","as","encoder","output","vector","``","out_enc","``",".","Defaults","to","128.","max_seq_len","(","int",")",":","Maximum","output","sequence","length",":","math",":","`","T","`",".","Defaults","to","40.","mask","(","bool",")",":","Whether","to","mask","input","features","according","to","``","img_meta","[","'valid_ratio","'","]","``",".","Defaults","to","True",".","return_feature","(","bool",")",":","Return","feature","or","logits","as","the","result",".","Defaults","to","True",".","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",".","Defaults","to","False",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
code: def __init__(
      self,
      dictionary: Union[Dictionary, Dict],
      module_loss: Optional[Dict] = None,
      postprocessor: Optional[Dict] = None,
      rnn_layers: int = 2,
      dim_input: int = 512,
      dim_model: int = 128,
      max_seq_len: int = 40,
      mask: bool = True,
      return_feature: bool = True,
      encode_value: bool = False,
      init_cfg: Optional[Union[Dict, Sequence[Dict]]] = None,
  ) -> None:
      super().__init__(
          dictionary=dictionary,
          module_loss=module_loss,
          postprocessor=postprocessor,
          max_seq_len=max_seq_len,
          init_cfg=init_cfg,
      )
  
      self.dim_input = dim_input
      self.dim_model = dim_model
      self.return_feature = return_feature
      self.encode_value = encode_value
      self.mask = mask
  
      self.embedding = nn.Embedding(
          self.max_seq_len + 1, self.dim_model
      )
  
      self.position_aware_module = PositionAwareLayer(
          self.dim_model, rnn_layers
      )
  
      self.attention_layer = DotProductAttentionLayer()
  
      self.prediction = None
      if not self.return_feature:
          self.prediction = nn.Linear(
              dim_model if encode_value else dim_input,
              self.dictionary.num_classes,
          )
      self.softmax = nn.Softmax(dim=-1)
  
file_path: mmocr/mmocr/models/textrecog/decoders/position_attention_decoder.py
imports: import math
  from typing import Dict, Optional, Sequence, Union
  import torch
  import torch.nn
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.models.textrecog.layers import DotProductAttentionLayer, PositionAwareLayer
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
  from .base import BaseDecoder
label_desc: Use image node_id 1 to create a new PositionAttentionDecoder object from inherited base classes: BaseDecoder with example: obj = PositionAttentionDecoder(dictionary, module_loss, postprocessor, rnn_layers, dim_input, dim_model, max_seq_len, mask, return_feature, encode_value, init_cfg)