code: def create_metadata_file(
      output_dir: Path,
      output_file_tmpl: str,
      metadata_file_name: Path,
      num_batches_per_tarfile: int,
  ) -> None:
      """
      Rename tar files according to template ``output_file_tmpl`` and save metadata file.
      Args:
          output_dir: a path to directory which contains initial tar files and where renamed tar files are saved
          output_file_tmpl: a template of a new tar file name
          metadata_file_name: a path to a file into which metadata is going to be saved
          num_batches_per_tarfile: a required number of batches in tar files. Used for checking that present tar files
              have correct number of batches
      """
      metadata = {"num_batches": 0, "tar_files": []}
      for i, fn in enumerate(
          [
              fn
              for fn in output_dir.iterdir()
              if TAR_FRAGMENT_PATTERN_FINISHED.match(fn.name)
          ]
      ):
          nb = int(
              TAR_FRAGMENT_PATTERN_FINISHED.match(fn.name).group(2)
          )
          assert nb == num_batches_per_tarfile
          new_name = output_dir / output_file_tmpl.format(
              ctr=i, num_batches=nb
          )
          fn.rename(new_name)
          metadata["tar_files"].append(new_name.name)
          metadata["num_batches"] += nb
      metadata[
          METADATA_PUNCT_LABEL_VOCAB_KEY
      ] = DEFAULT_PUNCT_LABEL_VOCAB_FILE_NAME
      metadata[
          METADATA_CAPIT_LABEL_VOCAB_KEY
      ] = DEFAULT_CAPIT_LABEL_VOCAB_FILE_NAME
      logging.info(
          f"{metadata['num_batches']} batches are in tarred dataset with metadata file {metadata_file_name}"
      )
      with metadata_file_name.open("w") as f:
          json.dump(metadata, f, indent=2)
  
imports: import inspect
  import json
  import multiprocessing
  import os
  import pickle
  import re
  import shutil
  import tempfile
  from collections import deque
  from pathlib import Path
  from typing import Any, Callable, Dict, Iterator, List, Optional, Set, Tuple, Type, Union
  import numpy
  import torch
  import webdataset
  from joblib import Parallel, delayed
  from omegaconf import DictConfig
  from torch.utils.data import IterableDataset
  from nemo.collections.common.tokenizers import TokenizerSpec
  from nemo.collections.nlp.data.token_classification.punctuation_capitalization_dataset import LABEL_ID_DIR_FOR_NEMO_CHECKPOINT, BertPunctuationCapitalizationDataset, Progress, create_label_ids, create_masks_and_segment_ids, load_label_ids, raise_not_equal_labels_error
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.core.neural_types import AudioSignal, ChannelType, LabelsType, LengthsType, MaskType, NeuralType
  from nemo.utils import logging
label_desc: Use image node_id 14 for calling a global function with example usage: create_metadata_file(output_dir, output_file_tmpl, metadata_file_name, num_batches_per_tarfile) without return types