code: def main(args=None):
      """
      Main function for building con parser
  
      Processes args, calls the appropriate function for the chosen --mode
      """
      args = parse_args(args=args)
  
      utils.set_random_seed(args["seed"])
  
      logger.info(
          "Running constituency parser in %s mode", args["mode"]
      )
      logger.debug("Using device: %s", args["device"])
  
      model_save_each_file = None
      if args["save_each_name"]:
          model_save_each_file = os.path.join(
              args["save_dir"], args["save_each_name"]
          )
          try:
              model_save_each_file % 1
          except TypeError:
              # so models.pt -> models_0001.pt, etc
              pieces = os.path.splitext(model_save_each_file)
              model_save_each_file = pieces[0] + "_%04d" + pieces[1]
  
      model_load_file = args["save_name"]
      if args["load_name"]:
          if os.path.exists(args["load_name"]):
              model_load_file = args["load_name"]
          else:
              model_load_file = os.path.join(
                  args["save_dir"], args["load_name"]
              )
      elif args["load_package"]:
          if args["lang"] is None:
              lang_pieces = args["load_package"].split("_", maxsplit=1)
              try:
                  lang = constant.lang_to_langcode(lang_pieces[0])
              except ValueError as e:
                  raise ValueError(
                      "--lang not specified, and the start of the --load_package name, %s, is not a known language.  Please check the values of those parameters"
                      % args["load_package"]
                  ) from e
              args["lang"] = lang
              args["load_package"] = lang_pieces[1]
          stanza.download(
              args["lang"],
              processors="constituency",
              package={"constituency": args["load_package"]},
          )
          model_load_file = os.path.join(
              DEFAULT_MODEL_DIR,
              args["lang"],
              "constituency",
              args["load_package"] + ".pt",
          )
          if not os.path.exists(model_load_file):
              raise FileNotFoundError(
                  "Expected the downloaded model file for language %s package %s to be in %s, but there is nothing there.  Perhaps the package name doesn't exist?"
                  % (
                      args["lang"],
                      args["load_package"],
                      model_load_file,
                  )
              )
          else:
              logger.info(
                  "Model for language %s package %s is in %s",
                  args["lang"],
                  args["load_package"],
                  model_load_file,
              )
  
      # TODO: when loading a saved model, we should default to whatever
      # is in the model file for --retag_method, not the default for the language
      retag_pipeline = retagging.build_retag_pipeline(args)
  
      if args["mode"] == "train":
          trainer.train(
              args,
              model_load_file,
              model_save_each_file,
              retag_pipeline,
          )
      elif args["mode"] == "predict":
          trainer.evaluate(args, model_load_file, retag_pipeline)
      elif args["mode"] == "parse_text":
          trainer.load_model_parse_text(
              args, model_load_file, retag_pipeline
          )
      elif args["mode"] == "remove_optimizer":
          trainer.remove_optimizer(
              args, args["save_name"], model_load_file
          )
  
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 4 for calling a global function with example usage: main(args) without return types