class_docstr: Transformer Decoder block with self attention mechanism.
  
  Args:
      n_layers (int): Number of attention layers. Defaults to 6.
      d_embedding (int): Language embedding dimension. Defaults to 512.
      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.
      d_inner (int): Hidden dimension of feedforward layers. Defaults to 256.
      n_position (int): Length of the positional encoding vector. Must be
          greater than ``max_seq_len``. Defaults to 200.
      dropout (float): Dropout rate for text embedding, MHSA, FFN. Defaults
          to 0.1.
      module_loss (dict, optional): Config to build module_loss. Defaults
          to None.
      postprocessor (dict, optional): Config to build postprocessor.
          Defaults to None.
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`.
      max_seq_len (int): Maximum output sequence length :math:`T`. Defaults
          to 30.
      init_cfg (dict or list[dict], optional): Initialization configs.
class_docstr_tok: ["Transformer","Decoder","block","with","self","attention","mechanism",".","Args",":","n_layers","(","int",")",":","Number","of","attention","layers",".","Defaults","to","6.","d_embedding","(","int",")",":","Language","embedding","dimension",".","Defaults","to","512.","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.","d_inner","(","int",")",":","Hidden","dimension","of","feedforward","layers",".","Defaults","to","256.","n_position","(","int",")",":","Length","of","the","positional","encoding","vector",".","Must","be","greater","than","``","max_seq_len","``",".","Defaults","to","200.","dropout","(","float",")",":","Dropout","rate","for","text","embedding",",","MHSA",",","FFN",".","Defaults","to","0.1.","module_loss","(","dict",",","optional",")",":","Config","to","build","module_loss",".","Defaults","to","None",".","postprocessor","(","dict",",","optional",")",":","Config","to","build","postprocessor",".","Defaults","to","None",".","dictionary","(","dict","or",":","obj",":","`","Dictionary","`",")",":","The","config","for","`","Dictionary","`","or","the","instance","of","`","Dictionary","`",".","max_seq_len","(","int",")",":","Maximum","output","sequence","length",":","math",":","`","T","`",".","Defaults","to","30.","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs","."]
docstr: Forward for training. Source mask will be used here.
  
  Args:
      feat (Tensor, optional): Unused.
      out_enc (Tensor): Encoder output of shape : math:`(N, T, D_m)`
          where :math:`D_m` is ``d_model``. Defaults to None.
      data_samples (list[TextRecogDataSample]): Batch of
          TextRecogDataSample, containing gt_text and valid_ratio
          information. Defaults to None.
  
  Returns:
      Tensor: The raw logit tensor. Shape :math:`(N, T, C)` where
      :math:`C` is ``num_classes``.
docstr_tok: ["Forward","for","training",".","Source","mask","will","be","used","here",".","Args",":","feat","(","Tensor",",","optional",")",":","Unused",".","out_enc","(","Tensor",")",":","Encoder","output","of","shape",":","math",":","`","(","N",",","T",",","D_m",")","`","where",":","math",":","`","D_m","`","is","``","d_model","``",".","Defaults","to","None",".","data_samples","(","list","[","TextRecogDataSample","]",")",":","Batch","of","TextRecogDataSample",",","containing","gt_text","and","valid_ratio","information",".","Defaults","to","None",".","Returns",":","Tensor",":","The","raw","logit","tensor",".","Shape",":","math",":","`","(","N",",","T",",","C",")","`","where",":","math",":","`","C","`","is","``","num_classes","``","."]
code: def forward_train(
      self,
      feat: Optional[torch.Tensor] = None,
      out_enc: torch.Tensor = None,
      data_samples: Sequence[TextRecogDataSample] = None,
  ) -> torch.Tensor:
      """Forward for training. Source mask will be used here.
  
      Args:
          feat (Tensor, optional): Unused.
          out_enc (Tensor): Encoder output of shape : math:`(N, T, D_m)`
              where :math:`D_m` is ``d_model``. Defaults to None.
          data_samples (list[TextRecogDataSample]): Batch of
              TextRecogDataSample, containing gt_text and valid_ratio
              information. Defaults to None.
  
      Returns:
          Tensor: The raw logit tensor. Shape :math:`(N, T, C)` where
          :math:`C` is ``num_classes``.
      """
      valid_ratios = []
      for data_sample in data_samples:
          valid_ratios.append(data_sample.get("valid_ratio"))
      src_mask = self._get_source_mask(out_enc, valid_ratios)
      trg_seq = []
      for data_sample in data_samples:
          trg_seq.append(
              data_sample.gt_text.padded_indexes.to(out_enc.device)
          )
      trg_seq = torch.stack(trg_seq, dim=0)
      attn_output = self._attention(trg_seq, out_enc, src_mask=src_mask)
      outputs = self.classifier(attn_output)
  
      return outputs
  
file_path: mmocr/mmocr/models/textrecog/decoders/nrtr_decoder.py
imports: import math
  from typing import Dict, List, Optional, Sequence, Union
  import torch
  import torch.nn
  from mmengine.model import ModuleList
  from mmocr.models.common import PositionalEncoding, TFDecoderLayer
  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 5 for calling the NRTRDecoder obj's underlying member method code with example usage: obj.forward_train(feat, out_enc, data_samples) and returns: outputs