class_docstr: Decoder for ABCNet.
  
  Args:
      in_channels (int): Number of input channels.
      dropout_prob (float): Probability of dropout. Default to 0.5.
      teach_prob (float): Probability of teacher forcing. Defaults to 0.5.
      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.
      max_seq_len (int, optional): Max sequence length. Defaults to 30.
      init_cfg (dict or list[dict], optional): Initialization configs.
          Defaults to None.
class_docstr_tok: ["Decoder","for","ABCNet",".","Args",":","in_channels","(","int",")",":","Number","of","input","channels",".","dropout_prob","(","float",")",":","Probability","of","dropout",".","Default","to","0.5.","teach_prob","(","float",")",":","Probability","of","teacher","forcing",".","Defaults","to","0.5.","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",".","max_seq_len","(","int",",","optional",")",":","Max","sequence","length",".","Defaults","to","30.","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","configs",".","Defaults","to","None","."]
docstr: Args:
      feat (Tensor): A Tensor of shape :math:`(N, C, 1, W)`.
      out_enc (torch.Tensor, optional): Encoder output. Defaults to None.
      data_samples (list[TextRecogDataSample], optional): Batch of
          TextRecogDataSample, containing gt_text information. Defaults
          to None.
  
  Returns:
      Tensor: The raw logit tensor. Shape :math:`(N, W, C)` where
      :math:`C` is ``num_classes``.
docstr_tok: ["Args",":","feat","(","Tensor",")",":","A","Tensor","of","shape",":","math",":","`","(","N",",","C",",","1",",","W",")","`",".","out_enc","(","torch.Tensor",",","optional",")",":","Encoder","output",".","Defaults","to","None",".","data_samples","(","list","[","TextRecogDataSample","]",",","optional",")",":","Batch","of","TextRecogDataSample",",","containing","gt_text","information",".","Defaults","to","None",".","Returns",":","Tensor",":","The","raw","logit","tensor",".","Shape",":","math",":","`","(","N",",","W",",","C",")","`","where",":","math",":","`","C","`","is","``","num_classes","``","."]
code: def forward_train(
      self,
      feat: torch.Tensor,
      out_enc: Optional[torch.Tensor] = None,
      data_samples: Optional[Sequence[TextRecogDataSample]] = None,
  ) -> torch.Tensor:
      """
      Args:
          feat (Tensor): A Tensor of shape :math:`(N, C, 1, W)`.
          out_enc (torch.Tensor, optional): Encoder output. Defaults to None.
          data_samples (list[TextRecogDataSample], optional): Batch of
              TextRecogDataSample, containing gt_text information. Defaults
              to None.
  
      Returns:
          Tensor: The raw logit tensor. Shape :math:`(N, W, C)` where
          :math:`C` is ``num_classes``.
      """
      bs = out_enc.size()[1]
      trg_seq = []
      for target in data_samples:
          trg_seq.append(target.gt_text.padded_indexes.to(feat.device))
      decoder_input = torch.zeros(bs).long().to(out_enc.device)
      trg_seq = torch.stack(trg_seq, dim=0)
      decoder_hidden = torch.zeros(1, bs, self.in_channels).to(
          out_enc.device
      )
      decoder_outputs = []
      for index in range(trg_seq.shape[1]):
          #  decoder_output (nbatch, ncls)
          decoder_output, decoder_hidden = self._attention(
              decoder_input, decoder_hidden, out_enc
          )
          teach_forcing = (
              True if random.random() > self.teach_prob else False
          )
          if teach_forcing:
              decoder_input = trg_seq[:, index]  # Teacher forcing
          else:
              _, topi = decoder_output.data.topk(1)
              decoder_input = topi.squeeze()
          decoder_outputs.append(decoder_output)
  
      return torch.stack(decoder_outputs, dim=1)
  
file_path: mmocr/projects/ABCNet/abcnet/model/abcnet_rec_decoder.py
imports: import random
  from typing import Dict, Optional, Sequence, Union
  import torch
  import torch.nn
  from torch.nn import functional
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.models.textrecog.decoders.base import BaseDecoder
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
label_desc: Use image node_id 2 for calling the ABCNetRecDecoder obj's underlying member method code with example usage: obj.forward_train(feat, out_enc, data_samples) and returns: torch