code: def build_argparse():
      parser = argparse.ArgumentParser()
      parser.add_argument(
          "--data_dir",
          type=str,
          default="data/ner",
          help="Directory of NER data.",
      )
      parser.add_argument(
          "--wordvec_dir",
          type=str,
          default="extern_data/word2vec",
          help="Directory of word vectors",
      )
      parser.add_argument(
          "--wordvec_file",
          type=str,
          default="",
          help="File that contains word vectors",
      )
      parser.add_argument(
          "--wordvec_pretrain_file",
          type=str,
          default=None,
          help="Exact name of the pretrain file to read",
      )
      parser.add_argument(
          "--train_file",
          type=str,
          default=None,
          help="Input file for data loader.",
      )
      parser.add_argument(
          "--eval_file",
          type=str,
          default=None,
          help="Input file for data loader.",
      )
      parser.add_argument(
          "--eval_output_file",
          type=str,
          default=None,
          help="Where to write results: text, gold, pred.  If None, no results file printed",
      )
  
      parser.add_argument(
          "--mode", default="train", choices=["train", "predict"]
      )
      parser.add_argument(
          "--finetune",
          action="store_true",
          help="Load existing model during `train` mode from `save_dir` path",
      )
      parser.add_argument(
          "--finetune_load_name",
          type=str,
          default=None,
          help="Model to load when finetuning",
      )
      parser.add_argument(
          "--train_classifier_only",
          action="store_true",
          help="In case of applying Transfer-learning approach and training only the classifier layer this will freeze gradient propagation for all other layers.",
      )
      parser.add_argument(
          "--shorthand", type=str, help="Treebank shorthand"
      )
  
      parser.add_argument("--hidden_dim", type=int, default=256)
      parser.add_argument("--char_hidden_dim", type=int, default=100)
      parser.add_argument("--word_emb_dim", type=int, default=100)
      parser.add_argument("--char_emb_dim", type=int, default=100)
      parser.add_argument("--num_layers", type=int, default=1)
      parser.add_argument("--char_num_layers", type=int, default=1)
      parser.add_argument(
          "--pretrain_max_vocab", type=int, default=100000
      )
      parser.add_argument(
          "--word_dropout",
          type=float,
          default=0.01,
          help="How often to remove a word at training time.  Set to a small value to train unk when finetuning word embeddings",
      )
      parser.add_argument("--locked_dropout", type=float, default=0.0)
      parser.add_argument("--dropout", type=float, default=0.5)
      parser.add_argument(
          "--rec_dropout",
          type=float,
          default=0,
          help="Word recurrent dropout",
      )
      parser.add_argument(
          "--char_rec_dropout",
          type=float,
          default=0,
          help="Character recurrent dropout",
      )
      parser.add_argument(
          "--char_dropout",
          type=float,
          default=0,
          help="Character-level language model dropout",
      )
      parser.add_argument(
          "--no_char",
          dest="char",
          action="store_false",
          help="Turn off training a character model.",
      )
      parser.add_argument(
          "--charlm",
          action="store_true",
          help="Turn on contextualized char embedding using pretrained character-level language model.",
      )
      parser.add_argument(
          "--charlm_save_dir",
          type=str,
          default="saved_models/charlm",
          help="Root dir for pretrained character-level language model.",
      )
      parser.add_argument(
          "--charlm_shorthand",
          type=str,
          default=None,
          help="Shorthand for character-level language model training corpus.",
      )
      parser.add_argument(
          "--charlm_forward_file",
          type=str,
          default=None,
          help="Exact path to use for forward charlm",
      )
      parser.add_argument(
          "--charlm_backward_file",
          type=str,
          default=None,
          help="Exact path to use for backward charlm",
      )
      parser.add_argument(
          "--char_lowercase",
          dest="char_lowercase",
          action="store_true",
          help="Use lowercased characters in character model.",
      )
      parser.add_argument(
          "--no_lowercase",
          dest="lowercase",
          action="store_false",
          help="Use cased word vectors.",
      )
      parser.add_argument(
          "--no_emb_finetune",
          dest="emb_finetune",
          action="store_false",
          help="Turn off finetuning of the embedding matrix.",
      )
      parser.add_argument(
          "--emb_finetune_known_only",
          dest="emb_finetune_known_only",
          action="store_true",
          help="Finetune the embedding matrix only for words in the embedding.  (Default: finetune words not in the embedding as well)  This may be useful for very large datasets where obscure words are only trained once in a while, such as French-WikiNER",
      )
      parser.add_argument(
          "--no_input_transform",
          dest="input_transform",
          action="store_false",
          help="Do not use input transformation layer before tagger lstm.",
      )
      parser.add_argument(
          "--scheme",
          type=str,
          default="bioes",
          help="The tagging scheme to use: bio or bioes.",
      )
      parser.add_argument(
          "--train_scheme",
          type=str,
          default=None,
          help="The tagging scheme to use when training: bio or bioes.  Overrides --scheme for the training set",
      )
  
      parser.add_argument(
          "--bert_model",
          type=str,
          default=None,
          help="Use an external bert model (requires the transformers package)",
      )
      parser.add_argument(
          "--no_bert_model",
          dest="bert_model",
          action="store_const",
          const=None,
          help="Don't use bert",
      )
      parser.add_argument(
          "--bert_finetune",
          default=False,
          action="store_true",
          help="Finetune the bert (or other transformer)",
      )
      parser.add_argument(
          "--no_bert_finetune",
          dest="bert_finetune",
          action="store_false",
          help="Don't finetune the bert (or other transformer)",
      )
      parser.add_argument(
          "--bert_learning_rate",
          default=1.0,
          type=float,
          help="Scale the learning rate for transformer finetuning by this much",
      )
  
      parser.add_argument(
          "--sample_train",
          type=float,
          default=1.0,
          help="Subsample training data.",
      )
      parser.add_argument(
          "--optim",
          type=str,
          default="sgd",
          help="sgd, adagrad, adam or adamax.",
      )
      parser.add_argument(
          "--lr", type=float, default=0.1, help="Learning rate."
      )
      parser.add_argument(
          "--min_lr",
          type=float,
          default=1e-4,
          help="Minimum learning rate to stop training.",
      )
      parser.add_argument(
          "--momentum", type=float, default=0, help="Momentum for SGD."
      )
      parser.add_argument(
          "--lr_decay", type=float, default=0.5, help="LR decay rate."
      )
      parser.add_argument(
          "--patience",
          type=int,
          default=3,
          help="Patience for LR decay.",
      )
  
      parser.add_argument(
          "--connect_output_layers",
          action="store_true",
          default=False,
          help="Connect one output layer to the input of the next output layer.  By default, those layers are all separate",
      )
      parser.add_argument(
          "--predict_tagset",
          type=int,
          default=None,
          help="Which tagset to predict if there are multiple tagsets.  Will default to 0.  Default of None allows the model to remember the value from training time, but be overridden at test time",
      )
  
      parser.add_argument(
          "--ignore_tag_scores",
          type=str,
          default=None,
          help="Which tags to ignore, if any, when scoring dev & test sets",
      )
  
      parser.add_argument("--max_steps", type=int, default=200000)
      parser.add_argument("--eval_interval", type=int, default=500)
      parser.add_argument("--batch_size", type=int, default=32)
      parser.add_argument(
          "--max_grad_norm",
          type=float,
          default=5.0,
          help="Gradient clipping.",
      )
      parser.add_argument(
          "--log_step",
          type=int,
          default=20,
          help="Print log every k steps.",
      )
      parser.add_argument(
          "--log_norms",
          action="store_true",
          default=False,
          help="Log the norms of all the parameters (noisy!)",
      )
      parser.add_argument(
          "--save_dir",
          type=str,
          default="saved_models/ner",
          help="Root dir for saving models.",
      )
      parser.add_argument(
          "--save_name",
          type=str,
          default="{shorthand}_{embedding}_{finetune}_nertagger.pt",
          help="File name to save the model",
      )
  
      parser.add_argument("--seed", type=int, default=1234)
      utils.add_device_args(parser)
  
      parser.add_argument(
          "--wandb",
          action="store_true",
          help="Start a wandb session and write the results of training.  Only applies to training.  Use --wandb_name instead to specify a name",
      )
      parser.add_argument(
          "--wandb_name",
          default=None,
          help="Name of a wandb session to start when training.  Will default to the dataset short name",
      )
      return parser
  
imports: import sys
  import os
  import time
  from datetime import datetime
  import argparse
  import logging
  import numpy
  import random
  import re
  import json
  import torch
  from torch import nn, optim
  from stanza.models.ner.data import DataLoader
  from stanza.models.ner.trainer import Trainer
  from stanza.models.ner import scorer
  from stanza.models.common import utils
  from stanza.models.common.pretrain import Pretrain
  from stanza.utils.conll import CoNLL
  from stanza.models.common.doc import *
  from stanza.models import _training_logging
  from stanza.utils.confusion import confusion_to_weighted_f1, format_confusion
label_desc: Use image node_id 1 for calling a global function with example usage: build_argparse() and returns: parser