class_docstr: Implement encoder for SATRN, see `SATRN.
  
  <https://arxiv.org/abs/1910.04396>`_.
  
  Args:
      n_layers (int): Number of attention layers. Defaults to 12.
      n_head (int): Number of parallel attention heads. Defaults to 8.
      d_k (int): Dimension of the key vector. Defaults to 64.
      d_v (int): Dimension of the value vector. Defaults to 64.
      d_model (int): Dimension :math:`D_m` of the input from previous model.
          Defaults to 512.
      n_position (int): Length of the positional encoding vector. Must be
          greater than ``max_seq_len``. Defaults to 100.
      d_inner (int): Hidden dimension of feedforward layers. Defaults to 256.
      dropout (float): Dropout rate. Defaults to 0.1.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["Implement","encoder","for","SATRN",",","see","`","SATRN",".","<","https",":","\/\/arxiv.org\/abs\/1910.04396",">","`","_",".","Args",":","n_layers","(","int",")",":","Number","of","attention","layers",".","Defaults","to","12.","n_head","(","int",")",":","Number","of","parallel","attention","heads",".","Defaults","to","8.","d_k","(","int",")",":","Dimension","of","the","key","vector",".","Defaults","to","64.","d_v","(","int",")",":","Dimension","of","the","value","vector",".","Defaults","to","64.","d_model","(","int",")",":","Dimension",":","math",":","`","D_m","`","of","the","input","from","previous","model",".","Defaults","to","512.","n_position","(","int",")",":","Length","of","the","positional","encoding","vector",".","Must","be","greater","than","``","max_seq_len","``",".","Defaults","to","100.","d_inner","(","int",")",":","Hidden","dimension","of","feedforward","layers",".","Defaults","to","256.","dropout","(","float",")",":","Dropout","rate",".","Defaults","to","0.1.","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
code: def __init__(
      self,
      n_layers: int = 12,
      n_head: int = 8,
      d_k: int = 64,
      d_v: int = 64,
      d_model: int = 512,
      n_position: int = 100,
      d_inner: int = 256,
      dropout: float = 0.1,
      init_cfg: Optional[Union[Dict, List[Dict]]] = None,
  ) -> None:
      super().__init__(init_cfg=init_cfg)
      self.d_model = d_model
      self.position_enc = Adaptive2DPositionalEncoding(
          d_hid=d_model,
          n_height=n_position,
          n_width=n_position,
          dropout=dropout,
      )
      self.layer_stack = ModuleList(
          [
              SATRNEncoderLayer(
                  d_model, d_inner, n_head, d_k, d_v, dropout=dropout
              )
              for _ in range(n_layers)
          ]
      )
      self.layer_norm = nn.LayerNorm(d_model)
  
file_path: mmocr/mmocr/models/textrecog/encoders/satrn_encoder.py
imports: import math
  from typing import Dict, List, Optional, Union
  import torch.nn
  from mmengine.model import ModuleList
  from torch import Tensor
  from mmocr.models.textrecog.layers import Adaptive2DPositionalEncoding, SATRNEncoderLayer
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
  from .base import BaseEncoder
label_desc: Use image node_id 1 to create a new SATRNEncoder object from inherited base classes: BaseEncoder with example: obj = SATRNEncoder(n_layers, n_head, d_k, d_v, d_model, n_position, d_inner, dropout, init_cfg)