class_docstr: Implementation Parallel Decoder module in `SAR.
  
  <https://arxiv.org/abs/1811.00751>`_.
  
  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.
      enc_bi_rnn (bool): If True, use bidirectional RNN in encoder.
          Defaults to False.
      dec_bi_rnn (bool): If True, use bidirectional RNN in decoder.
          Defaults to False.
      dec_rnn_dropout (float): Dropout of RNN layer in decoder.
          Defaults to 0.0.
      dec_gru (bool): If True, use GRU, else LSTM in decoder. Defaults to
          False.
      d_model (int): Dim of channels from backbone :math:`D_i`. Defaults
          to 512.
      d_enc (int): Dim of encoder RNN layer :math:`D_m`. Defaults to 512.
      d_k (int): Dim of channels of attention module. Defaults to 64.
      pred_dropout (float): Dropout probability of prediction layer. Defaults
          to 0.0.
      max_seq_len (int): Maximum sequence length for decoding. Defaults to
          30.
      mask (bool): If True, mask padding in feature map. Defaults to True.
      pred_concat (bool): If True, concat glimpse feature from
          attention with holistic feature and hidden state. Defaults to
          False.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["Implementation","Parallel","Decoder","module","in","`","SAR",".","<","https",":","\/\/arxiv.org\/abs\/1811.00751",">","`","_",".","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",".","enc_bi_rnn","(","bool",")",":","If","True",",","use","bidirectional","RNN","in","encoder",".","Defaults","to","False",".","dec_bi_rnn","(","bool",")",":","If","True",",","use","bidirectional","RNN","in","decoder",".","Defaults","to","False",".","dec_rnn_dropout","(","float",")",":","Dropout","of","RNN","layer","in","decoder",".","Defaults","to","0.0.","dec_gru","(","bool",")",":","If","True",",","use","GRU",",","else","LSTM","in","decoder",".","Defaults","to","False",".","d_model","(","int",")",":","Dim","of","channels","from","backbone",":","math",":","`","D_i","`",".","Defaults","to","512.","d_enc","(","int",")",":","Dim","of","encoder","RNN","layer",":","math",":","`","D_m","`",".","Defaults","to","512.","d_k","(","int",")",":","Dim","of","channels","of","attention","module",".","Defaults","to","64.","pred_dropout","(","float",")",":","Dropout","probability","of","prediction","layer",".","Defaults","to","0.0.","max_seq_len","(","int",")",":","Maximum","sequence","length","for","decoding",".","Defaults","to","30.","mask","(","bool",")",":","If","True",",","mask","padding","in","feature","map",".","Defaults","to","True",".","pred_concat","(","bool",")",":","If","True",",","concat","glimpse","feature","from","attention","with","holistic","feature","and","hidden","state",".","Defaults","to","False",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
code: def __init__(
      self,
      dictionary: Union[Dict, Dictionary],
      module_loss: Optional[Dict] = None,
      postprocessor: Optional[Dict] = None,
      enc_bi_rnn: bool = False,
      dec_bi_rnn: bool = False,
      dec_rnn_dropout: Union[int, float] = 0.0,
      dec_gru: bool = False,
      d_model: int = 512,
      d_enc: int = 512,
      d_k: int = 64,
      pred_dropout: float = 0.0,
      max_seq_len: int = 30,
      mask: bool = True,
      pred_concat: bool = False,
      init_cfg: Optional[Union[Dict, List[Dict]]] = None,
      **kwargs,
  ) -> None:
      super().__init__(
          dictionary=dictionary,
          module_loss=module_loss,
          max_seq_len=max_seq_len,
          postprocessor=postprocessor,
          init_cfg=init_cfg,
      )
  
      self.num_classes = self.dictionary.num_classes
      self.enc_bi_rnn = enc_bi_rnn
      self.d_k = d_k
      self.start_idx = self.dictionary.start_idx
      self.mask = mask
      self.pred_concat = pred_concat
  
      encoder_rnn_out_size = d_enc * (int(enc_bi_rnn) + 1)
      decoder_rnn_out_size = encoder_rnn_out_size * (
          int(dec_bi_rnn) + 1
      )
      # 2D attention layer
      self.conv1x1_1 = nn.Linear(decoder_rnn_out_size, d_k)
      self.conv3x3_1 = nn.Conv2d(
          d_model, d_k, kernel_size=3, stride=1, padding=1
      )
      self.conv1x1_2 = nn.Linear(d_k, 1)
  
      # Decoder RNN layer
      kwargs = dict(
          input_size=encoder_rnn_out_size,
          hidden_size=encoder_rnn_out_size,
          num_layers=2,
          batch_first=True,
          dropout=dec_rnn_dropout,
          bidirectional=dec_bi_rnn,
      )
      if dec_gru:
          self.rnn_decoder = nn.GRU(**kwargs)
      else:
          self.rnn_decoder = nn.LSTM(**kwargs)
  
      # Decoder input embedding
      self.embedding = nn.Embedding(
          self.num_classes,
          encoder_rnn_out_size,
          padding_idx=self.dictionary.padding_idx,
      )
  
      # Prediction layer
      self.pred_dropout = nn.Dropout(pred_dropout)
      if pred_concat:
          fc_in_channel = (
              decoder_rnn_out_size + d_model + encoder_rnn_out_size
          )
      else:
          fc_in_channel = d_model
      self.prediction = nn.Linear(fc_in_channel, self.num_classes)
      self.softmax = nn.Softmax(dim=-1)
  
imports: import math
  from typing import Dict, List, Optional, Sequence, Union
  import torch
  import torch.nn
  import torch.nn.functional
  from mmocr.models.common.dictionary import Dictionary
  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 ParallelSARDecoder object from inherited base classes: BaseDecoder with example: obj = ParallelSARDecoder(dictionary, module_loss, postprocessor, enc_bi_rnn, dec_bi_rnn, dec_rnn_dropout, dec_gru, d_model, d_enc, d_k, pred_dropout, max_seq_len, mask, pred_concat, init_cfg)