class_docstr: SPTS Decoder.
  
  Args:
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`.
      num_bins (int): Number of bins dividing the image. Defaults to 1000.
      n_head (int): Number of parallel attention heads. Defaults to 8.
      d_model (int): Dimension :math:`D_m` of the input from previous model.
          Defaults to 256.
      d_feedforward (int): Dimension of the feedforward layer.
          Defaults to 1024.
      normalize_before (bool): Whether to normalize the input before
          encoding/decoding. Defaults to True.
      max_num_text (int): Maximum number of text instances in a sample.
          Defaults to 60.
      module_loss (dict, optional): Config to build loss. Defaults to None.
      postprocessor (dict, optional): Config to build postprocessor.
          Defaults to None.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["SPTS","Decoder",".","Args",":","dictionary","(","dict","or",":","obj",":","`","Dictionary","`",")",":","The","config","for","`","Dictionary","`","or","the","instance","of","`","Dictionary","`",".","num_bins","(","int",")",":","Number","of","bins","dividing","the","image",".","Defaults","to","1000.","n_head","(","int",")",":","Number","of","parallel","attention","heads",".","Defaults","to","8.","d_model","(","int",")",":","Dimension",":","math",":","`","D_m","`","of","the","input","from","previous","model",".","Defaults","to","256.","d_feedforward","(","int",")",":","Dimension","of","the","feedforward","layer",".","Defaults","to","1024.","normalize_before","(","bool",")",":","Whether","to","normalize","the","input","before","encoding\/decoding",".","Defaults","to","True",".","max_num_text","(","int",")",":","Maximum","number","of","text","instances","in","a","sample",".","Defaults","to","60.","module_loss","(","dict",",","optional",")",":","Config","to","build","loss",".","Defaults","to","None",".","postprocessor","(","dict",",","optional",")",":","Config","to","build","postprocessor",".","Defaults","to","None",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
docstr: Forward for training.
  
  Args:
      feat (torch.Tensor, optional): The feature map from backbone of
          shape :math:`(N, E, H, W)`. Defaults to None.
      out_enc (torch.Tensor, optional): Encoder output. Defaults to None.
      data_samples (Sequence[TextRecogDataSample]): Batch of
          TextRecogDataSample, containing gt_text information. Defaults
          to None.
docstr_tok: ["Forward","for","training",".","Args",":","feat","(","torch.Tensor",",","optional",")",":","The","feature","map","from","backbone","of","shape",":","math",":","`","(","N",",","E",",","H",",","W",")","`",".","Defaults","to","None",".","out_enc","(","torch.Tensor",",","optional",")",":","Encoder","output",".","Defaults","to","None",".","data_samples","(","Sequence","[","TextRecogDataSample","]",")",":","Batch","of","TextRecogDataSample",",","containing","gt_text","information",".","Defaults","to","None","."]
code: def forward_train(
      self,
      feat: Optional[torch.Tensor] = None,
      out_enc: Optional[torch.Tensor] = None,
      data_samples: Optional[Sequence[TextSpottingDataSample]] = None,
  ) -> torch.Tensor:
      """Forward for training.
  
      Args:
          feat (torch.Tensor, optional): The feature map from backbone of
              shape :math:`(N, E, H, W)`. Defaults to None.
          out_enc (torch.Tensor, optional): Encoder output. Defaults to None.
          data_samples (Sequence[TextRecogDataSample]): Batch of
              TextRecogDataSample, containing gt_text information. Defaults
              to None.
      """
      mask, pos_embed, memory, query_embed = self._embed(
          out_enc, data_samples
      )
  
      padded_targets = [
          data_sample.gt_instances.padded_indexes
          for data_sample in data_samples
      ]
      padded_targets = torch.stack(padded_targets, dim=0).to(
          out_enc.device
      )
      # we don't need eos here
      tgt = self.embedding(padded_targets[:, :-1]).permute(1, 0, 2)
      hs = self.decoder(
          tgt,
          memory,
          memory_key_padding_mask=mask,
          pos=pos_embed,
          query_pos=query_embed[: len(tgt)],
          tgt_mask=self._generate_square_subsequent_mask(len(tgt)).to(
              tgt.device
          ),
      )
      return self.vocab_embed(hs[-1].transpose(0, 1))
  
imports: import copy
  from typing import Dict, List, Optional, Sequence, Union
  import torch
  import torch.nn.functional
  from torch import Tensor, nn
  from mmocr.models.common import Dictionary
  from mmocr.models.textrecog.decoders import BaseDecoder
  from mmocr.registry import MODELS
  from mmocr.utils.typing_utils import TextSpottingDataSample
  from .position_embedding import PositionEmbeddingSine
label_desc: Use image node_id 4 for calling the SPTSDecoder obj's underlying member method code with example usage: obj.forward_train(feat, out_enc, data_samples) and returns: self