code: def main(cfg):
      config = type("Config", (), {})()
      for key in cfg.keys():
          config.__setattr__(key, cfg.get(key))
      logger.info(config)
      config.logger = logger
      if not os.path.exists(
          os.path.join(utils.get_original_cwd(), cfg.save_path)
      ):
          os.makedirs(
              os.path.join(utils.get_original_cwd(), cfg.save_path)
          )
  
      if torch.cuda.is_available():
          torch.cuda.set_device(config.device)
  
      random.seed(config.seed)
      np.random.seed(config.seed)
      torch.manual_seed(config.seed)
      torch.cuda.manual_seed(config.seed)
      torch.backends.cudnn.benchmark = False
      torch.backends.cudnn.deterministic = True
  
      logger.info("Loading Data")
  
      processor = NerProcessor()
  
      train_examples = (
          processor.get_train_examples(
              os.path.join(utils.get_original_cwd(), config.data_dir)
          )
          if config.do_train
          else None
      )
      eval_examples = (
          processor.get_dev_examples(
              os.path.join(utils.get_original_cwd(), config.data_dir)
          )
          if config.do_eval
          else None
      )
      test_examples = (
          processor.get_test_examples(
              os.path.join(utils.get_original_cwd(), config.data_dir)
          )
          if config.do_predict
          else None
      )
      datasets, ori_data = data_loader.load_data_bert(
          config, train_examples, eval_examples, test_examples
      )
  
      config.updates_total = (
          len(datasets[0]) // config.batch_size * config.epochs
          if datasets[0]
          else 0
      )
  
      logger.info("Building Model")
      model = Model(config)
  
      model = model.cuda()
  
      trainer = Trainer(config, model)
  
      train_loader, dev_loader, test_loader = (
          DataLoader(
              dataset=dataset,
              batch_size=config.batch_size,
              collate_fn=data_loader.collate_fn,
              shuffle=i == 0,
              num_workers=4,
              drop_last=i == 0,
          )
          if dataset
          else None
          for i, dataset in enumerate(datasets)
      )
  
      if config.do_train:
          best_f1 = 0
          best_test_f1 = 0
          for i in range(config.epochs):
              logger.info("Epoch: {}".format(i))
              trainer.train(config, i, train_loader)
  
              if config.do_eval:
                  f1 = trainer.eval(config, i, dev_loader)
                  if f1 > best_f1:
                      best_f1 = f1
                      trainer.save(
                          os.path.join(
                              utils.get_original_cwd(),
                              config.save_path,
                              "pytorch_model.bin",
                          )
                      )
  
              if config.do_predict:
                  test_f1 = trainer.eval(
                      config, i, test_loader, is_test=True
                  )
                  best_test_f1 = max(best_test_f1, test_f1)
          if config.do_eval:
              logger.info("Best DEV F1: {:3.4f}".format(best_f1))
          if config.do_predict:
              logger.info("Best TEST F1: {:3.4f}".format(best_test_f1))
      else:
          trainer.load(
              os.path.join(
                  utils.get_original_cwd(),
                  config.save_path,
                  "pytorch_model.bin",
              )
          )
  
          if config.do_eval:
              f1 = trainer.eval(config, config.epochs, dev_loader)
              logger.info("DEV F1: {:3.4f}".format(f1))
          if config.do_predict:
              test_f1 = trainer.eval(
                  config, config.epochs, test_loader, is_test=True
              )
              logger.info("TEST F1: {:3.4f}".format(test_f1))
  
imports: import argparse
  import json
  import numpy
  import prettytable
  import torch
  import torch.autograd
  import torch.nn
  import transformers
  from sklearn.metrics import precision_recall_fscore_support, f1_score, classification_report
  from torch.utils.data import DataLoader
  import hydra
  from deepke.name_entity_re.standard.w2ner import *
  from deepke.name_entity_re.standard.w2ner.utils import *
  from deepke.name_entity_re.standard.tools import *
label_desc: Use image node_id 1 for calling a global function with example usage: main(cfg) without return types