class_docstr: Transformer Encoder block with self attention mechanism.
  
  Args:
      n_layers (int): The number of sub-encoder-layers in the encoder.
          Defaults to 6.
      n_head (int): The number of heads in the multiheadattention models
          Defaults to 8.
      d_k (int): Total number of features in key. Defaults to 64.
      d_v (int): Total number of features in value. Defaults to 64.
      d_model (int): The number of expected features in the decoder inputs.
          Defaults to 512.
      d_inner (int): The dimension of the feedforward network model.
          Defaults to 256.
      dropout (float): Dropout rate for MHSA and FFN. Defaults to 0.1.
      init_cfg (dict or list[dict], optional): Initialization configs.
code: def __init__(
      self,
      n_layers: int = 6,
      n_head: int = 8,
      d_k: int = 64,
      d_v: int = 64,
      d_model: int = 512,
      d_inner: int = 256,
      dropout: float = 0.1,
      init_cfg: Optional[Union[Dict, Sequence[Dict]]] = None,
  ) -> None:
      super().__init__(init_cfg=init_cfg)
      self.d_model = d_model
      self.layer_stack = ModuleList(
          [
              TFEncoderLayer(
                  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/nrtr_encoder.py
imports: import math
  from typing import Dict, Optional, Sequence, Union
  import torch
  import torch.nn
  from mmengine.model import ModuleList
  from mmocr.models.common import TFEncoderLayer
  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 NRTREncoder object from inherited base classes: BaseEncoder with example: obj = NRTREncoder(n_layers, n_head, d_k, d_v, d_model, d_inner, dropout, init_cfg)