code: def main():
      args = parse_args()
      utils.log_training_args(args, logger, name="ensemble")
      retag_pipeline = retagging.build_retag_pipeline(args)
      foundation_cache = (
          retag_pipeline[0].foundation_cache
          if retag_pipeline
          else FoundationCache()
      )
  
      ensemble = Ensemble(args["models"], args, foundation_cache)
      ensemble.eval()
  
      if args["mode"] == "predict":
          with EvaluateParser() as evaluator:
              treebank = tree_reader.read_treebank(args["eval_file"])
              logger.info("Read %d trees for evaluation", len(treebank))
  
              if retag_pipeline is not None:
                  logger.info(
                      "Retagging trees using the %s tags from the %s package...",
                      args["retag_method"],
                      args["retag_package"],
                  )
                  retagged_treebank = retag_trees(
                      treebank, retag_pipeline, args["retag_xpos"]
                  )
                  logger.info("Retagging finished")
  
              f1, kbestF1 = run_dev_set(
                  ensemble, retagged_treebank, treebank, args, evaluator
              )
              logger.info("F1 score on %s: %f", args["eval_file"], f1)
              if kbestF1 is not None:
                  logger.info(
                      "KBest F1 score on %s: %f",
                      args["eval_file"],
                      kbestF1,
                  )
      elif args["mode"] == "parse_text":
          if args["tokenized_dir"]:
              if not args["predict_dir"]:
                  raise ValueError(
                      "Must specific --predict_dir to go with --tokenized_dir"
                  )
              parse_dir(
                  args,
                  ensemble,
                  retag_pipeline,
                  args["tokenized_dir"],
                  args["predict_dir"],
              )
          else:
              parse_text(args, ensemble, retag_pipeline)
      else:
          raise ValueError("Unhandled mode %s" % args["mode"])
  
imports: import argparse
  import logging
  import os
  import torch
  from stanza.models.common import utils
  from stanza.models.common.foundation_cache import FoundationCache
  from stanza.models.constituency import parse_transitions
  from stanza.models.constituency import retagging
  from stanza.models.constituency import tree_reader
  from stanza.models.constituency.trainer import Trainer, run_dev_set, parse_text, parse_dir
  from stanza.models.constituency.utils import add_predict_output_args, postprocess_predict_output_args, retag_trees
  from stanza.resources.common import DEFAULT_MODEL_DIR
  from stanza.server.parser_eval import EvaluateParser, ParseResult, ScoredTree
  from stanza.utils.default_paths import get_default_paths
label_desc: Use image node_id 2 for calling a global function with example usage: main() without return types