class_docstr: Transformer-based (duplex) decoder model for TN/ITN.
code: def _setup_dataloader_from_config(
      self, cfg: DictConfig, data_split: str
  ):
      logging.info(f"Creating {data_split} dataset")
  
      shuffle = cfg["shuffle"]
  
      if cfg.get("use_tarred_dataset", False):
          logging.info("Tarred dataset")
          metadata_file = cfg["tar_metadata_file"]
          if metadata_file is None or not os.path.exists(metadata_file):
              raise FileNotFoundError(
                  f"Trying to use tarred dataset but could not find {metadata_file}."
              )
  
          with open(metadata_file, "r") as f:
              metadata = json.load(f)
              num_batches = metadata["num_batches"]
              tar_files = os.path.join(
                  os.path.dirname(metadata_file),
                  metadata["text_tar_filepaths"],
              )
          logging.info(f"Loading {tar_files}")
  
          dataset = TarredTextNormalizationDecoderDataset(
              text_tar_filepaths=tar_files,
              num_batches=num_batches,
              shuffle_n=cfg.get("tar_shuffle_n", 4 * cfg["batch_size"])
              if shuffle
              else 0,
              shard_strategy=cfg.get("shard_strategy", "scatter"),
              global_rank=self.global_rank,
              world_size=self.world_size,
          )
  
          dl = torch.utils.data.DataLoader(
              dataset=dataset,
              batch_size=1,
              sampler=None,
              num_workers=cfg.get("num_workers", 2),
              pin_memory=cfg.get("pin_memory", False),
              drop_last=cfg.get("drop_last", False),
          )
      else:
          input_file = cfg.data_path
          if not os.path.exists(input_file):
              raise ValueError(f"{input_file} not found.")
  
          dataset = TextNormalizationDecoderDataset(
              input_file=input_file,
              tokenizer=self.tokenizer,
              tokenizer_name=self.transformer_name,
              mode=self.mode,
              max_len=self.max_sequence_len,
              decoder_data_augmentation=cfg.get(
                  "decoder_data_augmentation", False
              )
              if data_split == "train"
              else False,
              lang=self.lang,
              use_cache=cfg.get("use_cache", False),
              max_insts=cfg.get("max_insts", -1),
              do_tokenize=True,
          )
  
          # create and save class names to class_ids mapping for validation
          # (each validation set might have different classes)
          if data_split in ["val", "test"]:
              if not hasattr(self, "_val_class_to_id"):
                  self._val_class_to_id = []
                  self._val_id_to_class = []
              self._val_class_to_id.append(dataset.label_ids_semiotic)
              self._val_id_to_class.append(
                  {v: k for k, v in dataset.label_ids_semiotic.items()}
              )
  
          data_collator = DataCollatorForSeq2Seq(
              self.tokenizer,
              model=self.model,
              label_pad_token_id=constants.LABEL_PAD_TOKEN_ID,
              padding=True,
          )
          dl = torch.utils.data.DataLoader(
              dataset=dataset,
              batch_size=cfg.batch_size,
              shuffle=shuffle,
              collate_fn=data_collator,
              num_workers=cfg.get("num_workers", 3),
              pin_memory=cfg.get("pin_memory", False),
              drop_last=cfg.get("drop_last", False),
          )
  
      return dataset, dl
  
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 18 for calling the DuplexDecoderModel obj's underlying member method code with example usage: obj._setup_dataloader_from_config(cfg, data_split) and returns: dataset,  dl