code: def build_model(cls, args: argparse.Namespace) -> ESPnetUASRModel:
      assert check_argument_types()
      if isinstance(args.token_list, str):
          with open(args.token_list, encoding="utf-8") as f:
              token_list = [line.rstrip() for line in f]
  
          # Overwriting token_list to keep it as "portable".
          args.token_list = list(token_list)
      elif isinstance(args.token_list, (tuple, list)):
          token_list = list(args.token_list)
      else:
          raise RuntimeError("token_list must be str or list")
      vocab_size = len(token_list)
      logging.info(f"Vocabulary size: {vocab_size}")
  
      # load from fairseq checkpoint
      load_fairseq_model = False
      cfg = None
      if args.fairseq_checkpoint is not None:
          load_fairseq_model = True
          ckpt = args.fairseq_checkpoint
          logging.info(f"Loading parameters from fairseq: {ckpt}")
  
          state_dict = torch.load(ckpt)
          if "cfg" in state_dict and state_dict["cfg"] is not None:
              model_cfg = state_dict["cfg"]["model"]
              logging.info(f"Building model from {model_cfg}")
          else:
              raise RuntimeError(f"Bad 'cfg' in state_dict of {ckpt}")
  
      # 1. frontend
      if args.write_collected_feats:
          # Extract features in the model
          # Note(jiatong): if we use write_collected_feats=True (we use
          #                pre-extracted feature for training): we still initial
          #                frontend to allow inference with raw speech signal
          #                but the frontend is not used in training
          frontend_class = frontend_choices.get_class(args.frontend)
          frontend = frontend_class(**args.frontend_conf)
          if args.input_size is None:
              input_size = frontend.output_size()
          else:
              input_size = args.input_size
      else:
          # Give features from data-loader
          args.frontend = None
          args.frontend_conf = {}
          frontend = None
          input_size = args.input_size
  
      # 2. Segmenter
      if args.segmenter is not None:
          segmenter_class = segmenter_choices.get_class(args.segmenter)
          segmenter = segmenter_class(cfg=cfg, **args.segmenter_conf)
      else:
          segmenter = None
  
      # 3. Discriminator
      discriminator_class = discriminator_choices.get_class(
          args.discriminator
      )
      discriminator = discriminator_class(
          cfg=cfg, input_dim=vocab_size, **args.discriminator_conf
      )
  
      # 4. Generator
      generator_class = generator_choices.get_class(args.generator)
      generator = generator_class(
          cfg=cfg,
          input_dim=input_size,
          output_dim=vocab_size,
          **args.generator_conf,
      )
  
      # 5. Loss definition
      losses = {}
      if getattr(args, "losses", None) is not None:
          # This check is for the compatibility when load models
          # that packed by older version
          for ctr in args.losses:
              logging.info("initialize loss: {}".format(ctr["name"]))
              if ctr["name"] == "gradient_penalty":
                  loss = loss_choices.get_class(ctr["name"])(
                      discriminator=discriminator, **ctr["conf"]
                  )
              else:
                  loss = loss_choices.get_class(ctr["name"])(
                      **ctr["conf"]
                  )
              losses[ctr["name"]] = loss
  
      # 6. Build model
      logging.info(f"kenlm_path is: {args.kenlm_path}")
      model = ESPnetUASRModel(
          cfg=cfg,
          frontend=frontend,
          segmenter=segmenter,
          discriminator=discriminator,
          generator=generator,
          losses=losses,
          kenlm_path=args.kenlm_path,
          token_list=args.token_list,
          max_epoch=args.max_epoch,
          vocab_size=vocab_size,
          use_collected_training_feats=args.write_collected_feats,
      )
  
      # FIXME(kamo): Should be done in model?
      # 7. Initialize
      if load_fairseq_model:
          logging.info(f"Initializing model from {ckpt}")
          model.load_state_dict(state_dict["model"], strict=False)
      else:
          if args.init is not None:
              initialize(model, args.init)
  
      assert check_return_type(model)
      return model
  
imports: import argparse
  import logging
  from typing import Callable, Collection, Dict, List, Optional, Tuple
  import numpy
  import torch
  from typeguard import check_argument_types, check_return_type
  from espnet2.asr.frontend.abs_frontend import AbsFrontend
  from espnet2.asr.frontend.default import DefaultFrontend
  from espnet2.asr.frontend.fused import FusedFrontends
  from espnet2.asr.frontend.s3prl import S3prlFrontend
  from espnet2.asr.frontend.windowing import SlidingWindow
  from espnet2.tasks.abs_task import AbsTask, optim_classes
  from espnet2.torch_utils.initialize import initialize
  from espnet2.train.class_choices import ClassChoices
  from espnet2.train.collate_fn import CommonCollateFn
  from espnet2.train.preprocessor import CommonPreprocessor
  from espnet2.train.uasr_trainer import UASRTrainer
  from espnet2.uasr.discriminator.abs_discriminator import AbsDiscriminator
  from espnet2.uasr.discriminator.conv_discriminator import ConvDiscriminator
  from espnet2.uasr.espnet_model import ESPnetUASRModel
  from espnet2.uasr.generator.abs_generator import AbsGenerator
  from espnet2.uasr.generator.conv_generator import ConvGenerator
  from espnet2.uasr.loss.abs_loss import AbsUASRLoss
  from espnet2.uasr.loss.discriminator_loss import UASRDiscriminatorLoss
  from espnet2.uasr.loss.gradient_penalty import UASRGradientPenalty
  from espnet2.uasr.loss.phoneme_diversity_loss import UASRPhonemeDiversityLoss
  from espnet2.uasr.loss.pseudo_label_loss import UASRPseudoLabelLoss
  from espnet2.uasr.loss.smoothness_penalty import UASRSmoothnessPenalty
  from espnet2.uasr.segmenter.abs_segmenter import AbsSegmenter
  from espnet2.uasr.segmenter.join_segmenter import JoinSegmenter
  from espnet2.utils.nested_dict_action import NestedDictAction
  from espnet2.utils.types import int_or_none, str2bool, str_or_none
label_desc: Use image node_id 6 for calling the UASRTask obj's underlying member method code with example usage: obj.build_model(cls, args) and returns: model