class_docstr: Base recognition 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.
code: def __init__(
      self,
      dictionary: Union[Dict, Dictionary],
      max_seq_len: int = 40,
      letter_case: str = "unchanged",
      pad_with: str = "auto",
      **kwargs,
  ) -> None:
      super().__init__()
      if isinstance(dictionary, dict):
          self.dictionary = TASK_UTILS.build(dictionary)
      elif isinstance(dictionary, Dictionary):
          self.dictionary = dictionary
      else:
          raise TypeError(
              "The type of dictionary should be `Dictionary` or dict, "
              f"but got {type(dictionary)}"
          )
      self.max_seq_len = max_seq_len
      assert letter_case in ["unchanged", "upper", "lower"]
      self.letter_case = letter_case
  
      assert pad_with in ["auto", "padding", "end", "none"]
      if pad_with == "auto":
          self.pad_idx = (
              self.dictionary.padding_idx or self.dictionary.end_idx
          )
      elif pad_with == "padding":
          self.pad_idx = self.dictionary.padding_idx
      elif pad_with == "end":
          self.pad_idx = self.dictionary.end_idx
      else:
          self.pad_idx = None
      if self.pad_idx is None and pad_with != "none":
          if pad_with == "auto":
              raise ValueError(
                  'pad_with="auto", but dictionary.end_idx'
                  " and dictionary.padding_idx are both None"
              )
          else:
              raise ValueError(
                  f'pad_with="{pad_with}", but dictionary.{pad_with}_idx is'
                  " None"
              )
  
file_path: mmocr/mmocr/models/textrecog/module_losses/base.py
imports: from typing import Dict, Sequence, Union
  import torch
  import torch.nn
  from mmocr.models.common.dictionary import Dictionary
  from mmocr.registry import TASK_UTILS
  from mmocr.structures import TextRecogDataSample
label_desc: Use image node_id 1 to create a new BaseTextRecogModuleLoss object from inherited base classes: nn with example: obj = BaseTextRecogModuleLoss(dictionary, max_seq_len, letter_case, pad_with)