class_docstr: Transformer-based (duplex) decoder model for TN/ITN.
code: def __init__(self, cfg: DictConfig, trainer: Trainer = None):
      # Get global rank and total number of GPU workers for IterableDataset partitioning, if applicable
      # Global_rank and local_rank is set by LightningModule in Lightning 1.2.0
      self.world_size = 1
      if trainer is not None:
          self.world_size = trainer.num_nodes * trainer.num_devices
  
      self.tokenizer = AutoTokenizer.from_pretrained(cfg.tokenizer)
  
      super().__init__(cfg=cfg, trainer=trainer, no_lm_init=True)
      self.model = AutoModelForSeq2SeqLM.from_pretrained(
          cfg.transformer
      )
      self.max_sequence_len = cfg.get(
          "max_sequence_len", self.tokenizer.model_max_length
      )
      self.mode = cfg.get("mode", "joint")
  
      self.transformer_name = cfg.transformer
  
      # Language
      self.lang = cfg.get("lang", None)
  
      # Covering Grammars
      self.cg_normalizer = None  # Default
      # We only support integrating with English TN covering grammars at the moment
      self.use_cg = (
          cfg.get("use_cg", False) and self.lang == constants.ENGLISH
      )
      if self.use_cg:
          self.setup_cgs(cfg)
  
      # setup processor for detokenization
      self.processor = MosesProcessor(lang_id=self.lang)
  
imports: import json
  import os
  from collections import defaultdict
  from math import ceil
  from typing import Dict, List, Optional, Union
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, DataCollatorForSeq2Seq
  import nemo.collections.nlp.data.text_normalization.constants
  from nemo.collections.common.tokenizers.moses_tokenizers import MosesProcessor
  from nemo.collections.nlp.data.text_normalization import TextNormalizationTestDataset
  from nemo.collections.nlp.data.text_normalization.decoder_dataset import TarredTextNormalizationDecoderDataset, TextNormalizationDecoderDataset
  from nemo.collections.nlp.models.duplex_text_normalization.utils import get_formatted_string
  from nemo.collections.nlp.models.nlp_model import NLPModel
  from nemo.core.classes.common import PretrainedModelInfo, typecheck
  from nemo.core.neural_types import ChannelType, LabelsType, LossType, MaskType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 3 to create a new DuplexDecoderModel object from inherited base classes: NLPModel with example: obj = DuplexDecoderModel(cfg, trainer)