code: def _write_batches_to_tarfiles(
      input_file: str,
      tokenizer: AutoTokenizer,
      tokenizer_name: str,
      mode: str,
      lang: str,
      max_seq_len: int,
      batch_size: int,
      out_dir: str,
      num_batches_per_tarfile: int,
      decoder_data_augmentation: bool = False,
  ):
      """
      Creates tar files for the input file, i.e.:
          1. Creates a TextNormalizationDecoderDataset from the input file
          2. Constructs batches of size `batch_size`
          3. Saves each created batch to a pickle file and then adds `num_batches_per_tarfile`
              of the pickle files to a tarfile.
  
      Args:
          input_file: path to cleaned data file. See en/data_processing.py for cleaning.
          tokenizer: tokenizer
          tokenizer_name: the name of the tokenizer, usually corresponds to the pre-trained LM
          mode: model training mode
          max_seq_len: maximum length of the sequence (examples that are longer will be discarded)
          batch_size: batch size
          out_dir: path to output directory
          num_batches_per_tarfile: number of batches saved in each tar file
          decoder_data_augmentation: Set to True to enable data augmentation for the decoder model
          lang: data language
      """
  
      dataset = TextNormalizationDecoderDataset(
          input_file=input_file,
          raw_instances=_preprocess_file(input_file=input_file),
          tokenizer=tokenizer,
          tokenizer_name=tokenizer_name,
          mode=mode,
          max_len=max_seq_len,
          decoder_data_augmentation=decoder_data_augmentation,
          lang=lang,
          use_cache=False,
          max_insts=-1,
          do_tokenize=False,
          initial_shuffle=True,
      )
      dataset.batchify(batch_size)
      file_name = os.path.basename(input_file)
      tar_file_ctr = 0
      tar_file_path = os.path.join(
          out_dir,
          "%s-batches.%d.%d.%d.tar"
          % (file_name, batch_size, max_seq_len, tar_file_ctr),
      )
      tar_file_ptr = tarfile.open(tar_file_path, "w")
      total_batch_ctr = 0
      batch_ctr = 0
      for batch in dataset.batches:
          total_batch_ctr += 1
          batch_ctr += 1
          pickle_file = os.path.join(
              out_dir, "%s-batch-%d.pkl" % (file_name, total_batch_ctr)
          )
  
          pickle.dump(batch, open(pickle_file, "wb"))
          tar_file_ptr.add(pickle_file)
          os.remove(pickle_file)
  
          if batch_ctr == num_batches_per_tarfile:
              tar_file_ctr += 1
              tar_file_ptr.close()
              tar_file_path = os.path.join(
                  out_dir,
                  f"%s-batches.%d.%d.%d.tar"
                  % (file_name, batch_size, max_seq_len, tar_file_ctr),
              )
              tar_file_ptr = tarfile.open(
                  tar_file_path,
                  "w",
              )
              batch_ctr = 0
  
      # return tar files paths that have batches remaining
      remainder_tar_file_path = tar_file_ptr.name
      tar_file_ptr.close()
  
      return total_batch_ctr, remainder_tar_file_path
  
file_path: NeMo/examples/nlp/duplex_text_normalization/data/create_tarred_dataset.py
imports: import argparse
  import json
  import os
  import pickle
  import random
  import tarfile
  from glob import glob
  from typing import List, Tuple
  from joblib import Parallel, delayed
  from tqdm import tqdm
  from transformers import AutoTokenizer
  import nemo.collections.nlp.data.text_normalization.constants
  from nemo.collections.nlp.data.text_normalization.decoder_dataset import TextNormalizationDecoderDataset
  from nemo.utils import logging
label_desc: Use image node_id 2 for calling a global function with example usage: _write_batches_to_tarfiles(input_file, tokenizer, tokenizer_name, mode, lang, max_seq_len, batch_size, out_dir, num_batches_per_tarfile, decoder_data_augmentation) and returns: total_batch_ctr,  remainder_tar_file_path