code: def main(args=None):
      args = parse_args(args)
      seed = utils.set_random_seed(args.seed)
      logger.info("Using random seed: %d" % seed)
  
      utils.ensure_dir(args.save_dir)
  
      save_name = args.save_name
      if not (save_name):
          save_name = args.base_name + "_" + args.shorthand + "_"
          save_name = save_name + "FS_%s_" % "_".join(
              [str(x) for x in args.filter_sizes]
          )
          save_name = save_name + "C_%d_" % args.filter_channels
          if model.config.fc_shapes:
              save_name = save_name + "FC_%s_" % "_".join(
                  [str(x) for x in model.config.fc_shapes]
              )
          save_name = save_name + "classifier.pt"
  
      # TODO: maybe the dataset needs to be in a torch data loader in order to
      # make cuda operations faster
      checkpoint_file = None
      if args.train:
          train_set = data.read_dataset(
              args.train_file, args.wordvec_type, args.min_train_len
          )
          logger.info("Using training set: %s" % args.train_file)
          logger.info(
              "Training set has %d labels"
              % len(data.dataset_labels(train_set))
          )
          tlogger.setLevel(logging.DEBUG)
  
          if args.checkpoint:
              checkpoint_file = utils.checkpoint_name(
                  args.save_dir, save_name, args.checkpoint_save_name
              )
      elif not args.load_name:
          if args.save_name:
              args.load_name = args.save_name
          else:
              raise ValueError(
                  "No model provided and not asked to train a model.  This makes no sense"
              )
      else:
          train_set = None
  
      if (
          args.train
          and checkpoint_file is not None
          and os.path.exists(checkpoint_file)
      ):
          trainer = Trainer.load(
              checkpoint_file, args, load_optimizer=args.train
          )
      elif args.load_name:
          trainer = Trainer.load(
              args.load_name, args, load_optimizer=args.train
          )
      else:
          trainer = Trainer.build_new_model(args, train_set)
  
      trainer.model.log_configuration()
  
      model_file = os.path.join(args.save_dir, save_name)
  
      if args.train:
          utils.log_training_args(args, logger)
  
          dev_set = data.read_dataset(
              args.dev_file, args.wordvec_type, min_len=None
          )
          logger.info("Using dev set: %s", args.dev_file)
          logger.info("Training set has %d items", len(train_set))
          logger.info("Dev set has %d items", len(dev_set))
          data.check_labels(trainer.model.labels, dev_set)
  
          train_model(
              trainer,
              model_file,
              checkpoint_file,
              args,
              train_set,
              dev_set,
              trainer.model.labels,
          )
  
      if args.log_norms:
          trainer.model.log_norms()
      test_set = data.read_dataset(
          args.test_file, args.wordvec_type, min_len=None
      )
      logger.info("Using test set: %s" % args.test_file)
      data.check_labels(trainer.model.labels, test_set)
  
      if args.test_remap_labels is None:
          predictions = dataset_predictions(trainer.model, test_set)
          confusion_matrix = confusion_dataset(
              predictions, test_set, trainer.model.labels
          )
          if args.output_predictions:
              logger.info("List of predictions: %s", predictions)
          logger.info(
              "Confusion matrix:\n{}".format(
                  format_confusion(
                      confusion_matrix, trainer.model.labels
                  )
              )
          )
          correct, total = confusion_to_accuracy(confusion_matrix)
          logger.info(
              "Macro f1: {}".format(
                  confusion_to_macro_f1(confusion_matrix)
              )
          )
      else:
          correct = score_dataset(
              trainer.model,
              test_set,
              remap_labels=args.test_remap_labels,
              forgive_unmapped_labels=args.forgive_unmapped_labels,
          )
          total = len(test_set)
      logger.info(
          "Test set: %d correct of %d examples.  Accuracy: %f"
          % (correct, total, correct / total)
      )
  
imports: import argparse
  import ast
  import logging
  import os
  import random
  import re
  from enum import Enum
  import torch
  import torch.nn
  from stanza.models.common import loss
  from stanza.models.common import utils
  from stanza.models.pos.vocab import CharVocab
  import stanza.models.classifiers.data
  from stanza.models.classifiers.trainer import Trainer
  from stanza.models.classifiers.utils import WVType, ExtraVectors, ModelType
  from stanza.utils.confusion import format_confusion, confusion_to_accuracy, confusion_to_macro_f1
label_desc: Use image node_id 11 for calling a global function with example usage: main(args) without return types