docstr: Build a new model instance.
docstr_tok: ["Build","a","new","model","instance","."]
code: def build_model(cls, args, task):
      """Build a new model instance."""
  
      if args.decoder_layers_to_keep:
          args.decoder_layers = len(
              args.decoder_layers_to_keep.split(",")
          )
  
      if safe_getattr(args, "max_target_positions", None) is None:
          args.max_target_positions = safe_getattr(
              args, "tokens_per_sample", DEFAULT_MAX_TARGET_POSITIONS
          )
  
      if args.character_embeddings:
          embed_tokens = CharacterTokenEmbedder(
              task.source_dictionary,
              eval(args.character_filters),
              args.character_embedding_dim,
              args.decoder_embed_dim,
              args.char_embedder_highway_layers,
          )
      elif args.adaptive_input:
          embed_tokens = AdaptiveInput(
              len(task.source_dictionary),
              task.source_dictionary.pad(),
              args.decoder_input_dim,
              args.adaptive_input_factor,
              args.decoder_embed_dim,
              options.eval_str_list(
                  args.adaptive_input_cutoff, type=int
              ),
              args.quant_noise_pq,
              args.quant_noise_pq_block_size,
          )
      else:
          embed_tokens = cls.build_embedding(
              args, task.source_dictionary, args.decoder_input_dim
          )
  
      if args.tie_adaptive_weights:
          assert args.adaptive_input
          assert (
              args.adaptive_input_factor == args.adaptive_softmax_factor
          )
          assert (
              args.adaptive_softmax_cutoff == args.adaptive_input_cutoff
          ), "{} != {}".format(
              args.adaptive_softmax_cutoff, args.adaptive_input_cutoff
          )
          assert args.decoder_input_dim == args.decoder_output_dim
  
      decoder = TransformerDecoder(
          args,
          task.target_dictionary,
          embed_tokens,
          no_encoder_attn=True,
      )
      return cls(decoder)
  
imports: from dataclasses import dataclass, field
  from typing import Optional
  from omegaconf import II
  from fairseq import options, utils
  from fairseq.dataclass import ChoiceEnum, FairseqDataclass
  from fairseq.models import FairseqLanguageModel, register_model, register_model_architecture
  from fairseq.models.transformer import DEFAULT_MIN_PARAMS_TO_WRAP, Embedding, TransformerDecoder
  from fairseq.modules import AdaptiveInput, CharacterTokenEmbedder
  from fairseq.utils import safe_getattr, safe_hasattr
label_desc: Use image node_id 3 for calling the TransformerLanguageModel obj's underlying member method code with example usage: obj.build_model(cls, args, task) and returns: cls