class_docstr: CTC-based grapheme-to-phoneme model.
class_docstr_tok: ["CTC-based","grapheme-to-phoneme","model","."]
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      self.world_size = 1
      if trainer is not None:
          self.world_size = trainer.num_nodes * trainer.num_devices
  
      self.mode = cfg.model_name.lower()
  
      self.supported_modes = ["byt5", "conformer_bpe"]
      if self.mode not in self.supported_modes:
          raise ValueError(
              f"{self.mode} is not supported, choose from {self.supported_modes}"
          )
  
      # Setup phoneme tokenizer
      self._setup_tokenizer(cfg.tokenizer)
  
      # Setup grapheme tokenizer
      self.tokenizer_grapheme = self.setup_grapheme_tokenizer(cfg)
  
      # Initialize vocabulary
      vocabulary = self.tokenizer.tokenizer.get_vocab()
      cfg.decoder.vocabulary = ListConfig(list(vocabulary.keys()))
      self.vocabulary = cfg.decoder.vocabulary
      self.labels_tkn2id = {l: i for i, l in enumerate(self.vocabulary)}
      self.labels_id2tkn = {i: l for i, l in enumerate(self.vocabulary)}
  
      super().__init__(cfg, trainer)
  
      self._setup_encoder()
      self.decoder = EncDecCTCModel.from_config_dict(self._cfg.decoder)
      self.loss = CTCLoss(
          num_classes=self.decoder.num_classes_with_blank - 1,
          zero_infinity=True,
          reduction=self._cfg.get("ctc_reduction", "mean_batch"),
      )
  
      # Setup decoding objects
      decoding_cfg = self.cfg.get("decoding", None)
  
      # In case decoding config not found, use default config
      if decoding_cfg is None:
          decoding_cfg = OmegaConf.structured(CTCBPEDecodingConfig)
          with open_dict(self.cfg):
              self.cfg.decoding = decoding_cfg
  
      self.decoding = CTCBPEDecoding(
          self.cfg.decoding, tokenizer=self.tokenizer
      )
  
      self.wer = WER(
          decoding=self.decoding,
          use_cer=False,
          log_prediction=False,
          dist_sync_on_step=True,
      )
      self.per = WER(
          decoding=self.decoding,
          use_cer=True,
          log_prediction=False,
          dist_sync_on_step=True,
      )
  
imports: import os
  import string
  from dataclasses import dataclass
  from typing import Any, Dict, List, Optional, Union
  import torch
  from hydra.utils import instantiate
  from omegaconf import DictConfig, ListConfig, OmegaConf, open_dict
  from pytorch_lightning import Trainer
  from transformers import AutoConfig, AutoModel, AutoTokenizer
  from nemo.collections.tts.g2p.data.ctc import CTCG2PBPEDataset
  from nemo.collections.tts.models.base import G2PModel
  from nemo.core.classes.common import PretrainedModelInfo
  from nemo.utils import logging
label_desc: Use image node_id 1 to create a new CTCG2PModel object from inherited base classes: G2PModel, ASRBPEMixin with example: obj = CTCG2PModel(cfg, trainer)