code: def main(args):
      cwd = utils.get_original_cwd()
      OmegaConf.set_struct(args, True)
      with open_dict(args):
          args["cwd"] = cwd
      args.data_dir = os.path.join(
          args.cwd, "./data/" + args.data_name + "/" + args.task_name
      )
      args.tag_path = os.path.join(
          args.cwd, "./data/" + args.data_name + "/schema"
      )
      args.output_dir = os.path.join(
          args.cwd,
          "./exp/"
          + args.data_name
          + "/"
          + args.task_name
          + "/"
          + args.model_name_or_path.split("/")[-1],
      )
      # args.model_name_or_path = os.path.join(args.cwd, args.model_name_or_path)
      args.do_predict = True if args.data_name == "ACE" else False
  
      if (
          os.path.exists(args.output_dir)
          and os.listdir(args.output_dir)
          and args.do_train
          and not args.overwrite_output_dir
      ):
          raise ValueError(
              "Output directory ({}) already exists and is not empty. Use --overwrite_output_dir to overcome.".format(
                  args.output_dir
              )
          )
  
      # Setup CUDA, GPU & distributed training
      if args.local_rank == -1 or args.no_cuda:
          device = torch.device(
              "cuda:0"
              if torch.cuda.is_available() and not args.no_cuda
              else "cpu"
          )
          args.n_gpu = torch.cuda.device_count()
          logger.info({"n_gpu: ": args.n_gpu})
  
      else:  # Initializes the distributed backend which will take care of sychronizing nodes/GPUs
          torch.cuda.set_device(args.local_rank)
          device = torch.device("cuda", args.local_rank)
          torch.distributed.init_process_group(backend="nccl")
          args.n_gpu = 1
  
      # OmegaConf.set_struct(args, True)
      # with open_dict(args):
      #     print(device)
      #     print(device.type)
      #     args["device"] = device
  
      # Setup logging
      logging.basicConfig(
          format="%(asctime)s - %(levelname)s - %(name)s -   %(message)s",
          datefmt="%m/%d/%Y %H:%M:%S",
          level=logging.INFO
          if args.local_rank in [-1, 0]
          else logging.WARN,
      )
      logger.warning(
          "Process rank: %s, device: %s, n_gpu: %s, distributed training: %s, 16-bits training: %s",
          args.local_rank,
          device,
          args.n_gpu,
          bool(args.local_rank != -1),
          args.fp16,
      )
  
      # Set seed
      set_seed(args)
  
      args.model_type = args.model_type.lower()
      config_class, model_class, tokenizer_class = MODEL_CLASSES[
          args.model_type
      ]
      # tokenizer
      tokenizer = tokenizer_class.from_pretrained(
          args.tokenizer_name
          if args.tokenizer_name
          else args.model_name_or_path,
          do_lower_case=args.do_lower_case,
          cache_dir=args.cache_dir if args.cache_dir else None,
      )
  
      pad_token_label_id = -100
      # get_processor
      processor = PROCESSORS[args.data_name](
          task_name=args.task_name, tokenizer=tokenizer
      )
  
      labels = processor.get_labels(args.tag_path)
      num_labels = len(labels)
      # Load pretrained model and tokenizer
      if args.local_rank not in [-1, 0]:
          torch.distributed.barrier()  # Make sure only the first process in distributed training will download model & vocab
  
      # config
      config = config_class.from_pretrained(
          args.config_name
          if args.config_name
          else args.model_name_or_path,
          num_labels=num_labels,
          cache_dir=args.cache_dir if args.cache_dir else None,
      )
  
      # load model
      ner_model = model_class.from_pretrained(
          args.model_name_or_path,
          from_tf=bool(".ckpt" in args.model_name_or_path),
          config=config,
          cache_dir=args.cache_dir if args.cache_dir else None,
      )
  
      if args.local_rank == 0:
          torch.distributed.barrier()  # Make sure only the first process in distributed training will download model & vocab
  
      ner_model.to(device)
  
      logger.info("Training/evaluation parameters %s", args)
  
      if args.do_train:
          train_examples = processor.get_examples(
              os.path.join(args.data_dir, "train.tsv"), "train"
          )
          train_dataset = load_and_cache_examples(
              args,
              train_examples,
              tokenizer,
              labels,
              pad_token_label_id,
              mode="train",
          )
  
      if args.do_eval:
          eval_examples = processor.get_examples(
              os.path.join(args.data_dir, "dev.tsv"), "dev"
          )
          eval_dataset = load_and_cache_examples(
              args,
              eval_examples,
              tokenizer,
              labels,
              pad_token_label_id,
              mode="dev",
          )
  
      if args.do_predict:
          test_examples = processor.get_examples(
              os.path.join(args.data_dir, "test.tsv"), "test"
          )
          test_dataset = load_and_cache_examples(
              args,
              test_examples,
              tokenizer,
              labels,
              pad_token_label_id,
              mode="test",
          )
  
      # Training
      if args.do_train:
          global_step, tr_loss = train(
              args=args,
              train_dataset=train_dataset if args.do_train else None,
              eval_dataset=eval_dataset if args.do_eval else None,
              model=ner_model,
              tokenizer=tokenizer,
              labels=labels,
              pad_token_label_id=pad_token_label_id,
              device=device,
          )
          print(
              " global_step = %s, average loss = %s",
              global_step,
              tr_loss,
          )
          logger.info(
              " global_step = %s, average loss = %s",
              global_step,
              tr_loss,
          )
  
      # Saving best-practices: if you use defaults names for the model, you can reload it using from_pretrained()
      if args.do_train and (
          args.local_rank == -1 or torch.distributed.get_rank() == 0
      ):
          # Create output directory if needed
          if not os.path.exists(
              args.output_dir
          ) and args.local_rank in [-1, 0]:
              os.makedirs(args.output_dir)
  
          logger.info("Saving model checkpoint to %s", args.output_dir)
          # Save a trained model, configuration and tokenizer using `save_pretrained()`.
          # They can then be reloaded using `from_pretrained()`
          model_to_save = (
              ner_model.module
              if hasattr(ner_model, "module")
              else ner_model
          )  # Take care of distributed/parallel training
          model_to_save.save_pretrained(args.output_dir)
          tokenizer.save_pretrained(args.output_dir)
  
          # Good practice: save your training arguments together with the trained model
          torch.save(
              args, os.path.join(args.output_dir, "training_args.bin")
          )
  
      # Evaluation
      results = {}
      if args.do_eval and args.local_rank in [-1, 0]:
          tokenizer = tokenizer_class.from_pretrained(
              args.output_dir, do_lower_case=args.do_lower_case
          )
          checkpoints = [args.output_dir]
          if args.eval_all_checkpoints:
              checkpoints = list(
                  os.path.dirname(c)
                  for c in sorted(
                      glob.glob(
                          args.output_dir + "/**/" + WEIGHTS_NAME,
                          recursive=True,
                      )
                  )
              )
              logging.getLogger(
                  "pytorch_transformers.modeling_utils"
              ).setLevel(
                  logging.WARN
              )  # Reduce logging
          logger.info(
              "Evaluate the following checkpoints: %s", checkpoints
          )
          for checkpoint in checkpoints:
              global_step = (
                  checkpoint.split("-")[-1]
                  if len(checkpoints) > 1
                  else ""
              )
              model = model_class.from_pretrained(checkpoint)
              model.to(device)
              result, eval_pred_list = evaluate(
                  args,
                  model,
                  eval_dataset,
                  tokenizer,
                  labels,
                  pad_token_label_id,
                  mode="dev",
                  device=device,
                  prefix=global_step,
              )
              if global_step:
                  result = {
                      "{}_{}".format(global_step, k): v
                      for k, v in result.items()
                  }
              results.update(result)
          output_eval_file = os.path.join(
              args.output_dir, "eval_results.txt"
          )
          output_eval_pred_file = os.path.join(
              args.output_dir, "eval_pred.json"
          )
          with open(output_eval_file, "w") as writer:
              for key in sorted(results.keys()):
                  writer.write(
                      "{} = {}\n".format(key, str(results[key]))
                  )
  
          # dump the trigger pred result of dev.
          json.dump(
              eval_pred_list,
              open(output_eval_pred_file, "w"),
              ensure_ascii=False,
          )
  
      if args.do_predict and args.local_rank in [-1, 0]:
          tokenizer = tokenizer_class.from_pretrained(
              args.output_dir, do_lower_case=args.do_lower_case
          )
          model = model_class.from_pretrained(args.output_dir)
          model.to(device)
          result, test_pred_list = evaluate(
              args,
              model,
              test_dataset,
              tokenizer,
              labels,
              pad_token_label_id,
              mode="test",
              device=device,
          )
          # Save results
          output_test_results_file = os.path.join(
              args.output_dir, "test_results.txt"
          )
          with open(output_test_results_file, "w") as writer:
              for key in sorted(result.keys()):
                  writer.write(
                      "{} = {}\n".format(key, str(result[key]))
                  )
          # Save predictions
          output_test_pred_file = os.path.join(
              args.output_dir, "test_pred.json"
          )
          json.dump(
              test_pred_list,
              open(output_test_pred_file, "w"),
              ensure_ascii=False,
          )
  
      return results
  
imports: import argparse
  import glob
  import logging
  import os
  import sys
  import json
  import random
  import numpy
  import torch
  import hydra
  from hydra import utils
  from omegaconf import OmegaConf, open_dict
  from seqeval.metrics import f1_score, precision_score, recall_score
  from torch.utils.data import DataLoader, RandomSampler, SequentialSampler, TensorDataset
  from torch.utils.data.distributed import DistributedSampler
  from tqdm import tqdm, trange
  from transformers import WEIGHTS_NAME, AdamW, BertConfig, BertTokenizer, get_linear_schedule_with_warmup
  from deepke.event_extraction.standard.bertcrf.processor_ee import convert_examples_to_features, PROCESSORS
  from deepke.event_extraction.standard.bertcrf.bert_crf import *
label_desc: Use image node_id 5 for calling a global function with example usage: main(args) and returns: results