class_docstr: Implementation of loss module for encoder-decoder based text recognition
  method with CrossEntropy loss.
  
  Args:
      dictionary (dict or :obj:`Dictionary`): The config for `Dictionary` or
          the instance of `Dictionary`.
      max_seq_len (int): Maximum sequence length. The sequence is usually
          generated from decoder. Defaults to 40.
      letter_case (str): There are three options to alter the letter cases
          of gt texts:
          - unchanged: Do not change gt texts.
          - upper: Convert gt texts into uppercase characters.
          - lower: Convert gt texts into lowercase characters.
          Usually, it only works for English characters. Defaults to
          'unchanged'.
      pad_with (str): The padding strategy for ``gt_text.padded_indexes``.
          Defaults to 'auto'. Options are:
          - 'auto': Use dictionary.padding_idx to pad gt texts, or
            dictionary.end_idx if dictionary.padding_idx
            is None.
          - 'padding': Always use dictionary.padding_idx to pad gt texts.
          - 'end': Always use dictionary.end_idx to pad gt texts.
          - 'none': Do not pad gt texts.
      ignore_char (int or str): Specifies a target value that is
          ignored and does not contribute to the input gradient.
          ignore_char can be int or str. If int, it is the index of
          the ignored char. If str, it is the character to ignore.
          Apart from single characters, each item can be one of the
          following reversed keywords: 'padding', 'start', 'end',
          and 'unknown', which refer to their corresponding special
          tokens in the dictionary. It will not ignore any special
          tokens when ignore_char == -1 or 'none'. Defaults to 'padding'.
      flatten (bool): Whether to flatten the output and target before
          computing CE loss. Defaults to False.
      reduction (str): Specifies the reduction to apply to the output,
          should be one of the following: ('none', 'mean', 'sum'). Defaults
          to 'none'.
      ignore_first_char (bool): Whether to ignore the first token in target (
          usually the start token). If ``True``, the last token of the output
          sequence will also be removed to be aligned with the target length.
          Defaults to ``False``.
      flatten (bool): Whether to flatten the vectors for loss computation.
          Defaults to False.
docstr: Args:
      outputs (Tensor): A raw logit tensor of shape :math:`(N, T, C)`.
      data_samples (list[TextRecogDataSample]): List of
          ``TextRecogDataSample`` which are processed by ``get_target``.
  
  Returns:
      dict: A loss dict with the key ``loss_ce``.
code: def forward(
      self,
      outputs: torch.Tensor,
      data_samples: Sequence[TextRecogDataSample],
  ) -> Dict:
      """
      Args:
          outputs (Tensor): A raw logit tensor of shape :math:`(N, T, C)`.
          data_samples (list[TextRecogDataSample]): List of
              ``TextRecogDataSample`` which are processed by ``get_target``.
  
      Returns:
          dict: A loss dict with the key ``loss_ce``.
      """
      targets = list()
      for data_sample in data_samples:
          targets.append(data_sample.gt_text.padded_indexes)
      targets = torch.stack(targets, dim=0).long()
      if self.ignore_first_char:
          targets = targets[:, 1:].contiguous()
          outputs = outputs[:, :-1, :].contiguous()
      if self.flatten:
          outputs = outputs.view(-1, outputs.size(-1))
          targets = targets.view(-1)
      else:
          outputs = outputs.permute(0, 2, 1).contiguous()
  
      loss_ce = self.loss_ce(outputs, targets.to(outputs.device))
      losses = dict(loss_ce=loss_ce)
  
      return losses
  
file_path: mmocr/mmocr/models/textrecog/module_losses/ce_module_loss.py
imports: import warnings
  from typing import Dict, Sequence, Union
  import torch
  import torch.nn
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.registry import MODELS
  from mmocr.structures import TextRecogDataSample
  from .base import BaseTextRecogModuleLoss
label_desc: Use image node_id 2 for calling the CEModuleLoss obj's underlying member method code with example usage: obj.forward(outputs, data_samples) and returns: losses