class_docstr: The class generates a dictionary for recognition. It pre-defines four
  special tokens: ``start_token``, ``end_token``, ``pad_token``, and
  ``unknown_token``, which will be sequentially placed at the end of the
  dictionary when their corresponding flags are True.
  
  Args:
      dict_file (str): The path of Character dict file which a single
          character must occupies a line.
      with_start (bool): The flag to control whether to include the start
          token. Defaults to False.
      with_end (bool): The flag to control whether to include the end token.
          Defaults to False.
      same_start_end (bool): The flag to control whether the start token and
          end token are the same. It only works when both ``with_start`` and
          ``with_end`` are True. Defaults to False.
      with_padding (bool):The padding token may represent more than a
          padding. It can also represent tokens like the blank token in CTC
          or the background token in SegOCR. Defaults to False.
      with_unknown (bool): The flag to control whether to include the
          unknown token. Defaults to False.
      start_token (str): The start token as a string. Defaults to '<BOS>'.
      end_token (str): The end token as a string. Defaults to '<EOS>'.
      start_end_token (str): The start/end token as a string. if start and
          end is the same. Defaults to '<BOS/EOS>'.
      padding_token (str): The padding token as a string.
          Defaults to '<PAD>'.
      unknown_token (str, optional): The unknown token as a string. If it's
          set to None and ``with_unknown`` is True, the unknown token will be
          skipped when converting string to index. Defaults to '<UKN>'.
code: def __init__(
      self,
      dict_file: str,
      with_start: bool = False,
      with_end: bool = False,
      same_start_end: bool = False,
      with_padding: bool = False,
      with_unknown: bool = False,
      start_token: str = "<BOS>",
      end_token: str = "<EOS>",
      start_end_token: str = "<BOS/EOS>",
      padding_token: str = "<PAD>",
      unknown_token: str = "<UKN>",
  ) -> None:
      self.with_start = with_start
      self.with_end = with_end
      self.same_start_end = same_start_end
      self.with_padding = with_padding
      self.with_unknown = with_unknown
      self.start_end_token = start_end_token
      self.start_token = start_token
      self.end_token = end_token
      self.padding_token = padding_token
      self.unknown_token = unknown_token
  
      assert isinstance(dict_file, str)
      self._dict = []
      for line_num, line in enumerate(list_from_file(dict_file)):
          line = line.strip("\r\n")
          if len(line) > 1:
              raise ValueError(
                  "Expect each line has 0 or 1 character, "
                  f"got {len(line)} characters "
                  f"at line {line_num + 1}"
              )
          if line != "":
              self._dict.append(line)
  
      self._char2idx = {
          char: idx for idx, char in enumerate(self._dict)
      }
  
      self._update_dict()
      assert len(set(self._dict)) == len(
          self._dict
      ), "Invalid dictionary: Has duplicated characters."
  
file_path: mmocr/mmocr/models/common/dictionary/dictionary.py
imports: from typing import List, Sequence
  from mmocr.registry import TASK_UTILS
  from mmocr.utils import list_from_file
label_desc: Use image node_id 1 to create a new Dictionary object  with example: obj = Dictionary(dict_file, with_start, with_end, same_start_end, with_padding, with_unknown, start_token, end_token, start_end_token, padding_token, unknown_token)