code: def parse_args(args=None):
      parser = build_argparse()
  
      args = parser.parse_args(args=args)
      if (
          not args.lang
          and args.shorthand
          and len(args.shorthand.split("_", maxsplit=1)) == 2
      ):
          args.lang = args.shorthand.split("_")[0]
  
      if args.stage1_bert_learning_rate is None:
          args.stage1_bert_learning_rate = args.bert_learning_rate
  
      if args.optim is None and args.mode == "train":
          if not args.multistage:
              # this seemed to work the best when not doing multistage
              args.optim = "adadelta"
          elif args.bert_finetune or args.stage1_bert_finetune:
              logger.info(
                  "Multistage training is set, optimizer is not chosen, and bert finetuning is active.  Will use AdamW as the second stage optimizer."
              )
              args.optim = "adamw"
          else:
              # if MADGRAD exists, use it
              # otherwise, adamw
              try:
                  import madgrad
  
                  args.optim = "madgrad"
                  logger.info(
                      "Multistage training is set, optimizer is not chosen, and MADGRAD is available.  Will use MADGRAD as the second stage optimizer."
                  )
              except ModuleNotFoundError as e:
                  logger.warning(
                      "Multistage training is set.  Best models are with MADGRAD, but it is not installed.  Will use AdamW for the second stage optimizer.  Consider installing MADGRAD"
                  )
                  args.optim = "adamw"
  
      if args.mode == "train":
          if args.learning_rate is None:
              args.learning_rate = DEFAULT_LEARNING_RATES.get(
                  args.optim.lower(), None
              )
          if args.learning_eps is None:
              args.learning_eps = DEFAULT_LEARNING_EPS.get(
                  args.optim.lower(), None
              )
          if args.learning_momentum is None:
              args.learning_momentum = DEFAULT_MOMENTUM.get(
                  args.optim.lower(), None
              )
          if args.learning_weight_decay is None:
              args.learning_weight_decay = DEFAULT_WEIGHT_DECAY.get(
                  args.optim.lower(), None
              )
  
          if args.stage1_learning_rate is None:
              args.stage1_learning_rate = DEFAULT_LEARNING_RATES[
                  "adadelta"
              ]
          if args.stage1_bert_finetune is None:
              args.stage1_bert_finetune = args.bert_finetune
  
          if args.learning_rate_min_lr is None:
              args.learning_rate_min_lr = args.learning_rate * 0.02
          if args.stage1_learning_rate_min_lr is None:
              args.stage1_learning_rate_min_lr = (
                  args.stage1_learning_rate * 0.02
              )
  
      if args.reduce_position is None:
          args.reduce_position = args.hidden_size // 4
  
      if args.num_tree_lstm_layers is None:
          if args.constituency_composition in (
              ConstituencyComposition.TREE_LSTM,
              ConstituencyComposition.TREE_LSTM_CX,
          ):
              args.num_tree_lstm_layers = 2
          else:
              args.num_tree_lstm_layers = 1
  
      if args.wandb_name or args.wandb_norm_regex:
          args.wandb = True
  
      args = vars(args)
  
      retagging.postprocess_args(args)
      postprocess_predict_output_args(args)
  
      model_save_file = build_model_filename(args)
      args["save_name"] = model_save_file
  
      if args["checkpoint"]:
          args["checkpoint_save_name"] = utils.checkpoint_name(
              args["save_dir"],
              model_save_file,
              args["checkpoint_save_name"],
          )
  
      return args
  
file_path: stanza/stanza/models/constituency_parser.py
imports: import argparse
  import logging
  import os
  import re
  import torch
  import stanza
  from stanza.models.common import constant
  from stanza.models.common import utils
  from stanza.models.constituency import retagging
  from stanza.models.constituency import trainer
  from stanza.models.constituency.lstm_model import ConstituencyComposition, SentenceBoundary, StackHistory
  from stanza.models.constituency.parse_transitions import TransitionScheme
  from stanza.models.constituency.utils import DEFAULT_LEARNING_EPS, DEFAULT_LEARNING_RATES, DEFAULT_MOMENTUM, DEFAULT_LEARNING_RHO, DEFAULT_WEIGHT_DECAY, NONLINEARITY, add_predict_output_args, postprocess_predict_output_args
  from stanza.resources.common import DEFAULT_MODEL_DIR
label_desc: Use image node_id 3 for calling a global function with example usage: parse_args(args) and returns: args