code: def build_vocab_from_args(args: argparse.Namespace):
      if not args.output_path.endswith(".tar.gz"):
          raise ValueError(
              "param 'output_path' should end with '.tar.gz'"
          )
  
      if os.path.exists(args.output_path) and not args.force:
          raise RuntimeError(
              f"{args.output_path} already exists. Use --force to overwrite."
          )
  
      output_directory = os.path.dirname(args.output_path)
      if len(output_directory) > 0:
          os.makedirs(output_directory, exist_ok=True)
  
      params = Params.from_file(args.param_path)
  
      with tempfile.TemporaryDirectory() as temp_dir:
          # Serializes the vocab to 'tempdir/vocabulary'.
          make_vocab_from_params(params, temp_dir)
  
          # The CacheFile context manager gives us a temporary file to write to.
          # On a successful exit from the context, it will rename the temp file to
          # the target `output_path`.
          with CacheFile(
              args.output_path, suffix=".tar.gz"
          ) as temp_archive:
              logger.info(
                  "Archiving vocabulary to %s", args.output_path
              )
  
              with tarfile.open(temp_archive.name, "w:gz") as archive:
                  vocab_dir = os.path.join(temp_dir, "vocabulary")
                  for fname in os.listdir(vocab_dir):
                      if fname.endswith(".lock"):
                          continue
                      archive.add(
                          os.path.join(vocab_dir, fname), arcname=fname
                      )
  
      print(f"Success! Vocab saved to {args.output_path}")
      print(
          'You can now set the "vocabulary" entry of your training config to:'
      )
      print(
          json.dumps(
              {
                  "type": "from_files",
                  "directory": os.path.abspath(args.output_path),
              }
          )
      )
  
file_path: allennlp/allennlp/commands/build_vocab.py
imports: import argparse
  import json
  import logging
  import os
  import tarfile
  import tempfile
  from allennlp.commands.subcommand import Subcommand
  from allennlp.common.file_utils import CacheFile
  from allennlp.common.params import Params
  from allennlp.training.util import make_vocab_from_params
label_desc: Use image node_id 1 for calling a global function with example usage: build_vocab_from_args(args) without return types