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."""
      # make sure that all args are properly defaulted
      # (in case there are any new ones)
      cloze_transformer_architecture(args)
  
      src_dict, tgt_dict = (
          task.source_dictionary,
          task.target_dictionary,
      )
  
      if args.share_all_embeddings:
          if src_dict != tgt_dict:
              raise RuntimeError(
                  "--share-all-embeddings requires a joined dictionary"
              )
          if args.encoder_embed_dim != args.decoder_embed_dim:
              raise RuntimeError(
                  "--share-all-embeddings requires --encoder-embed-dim "
                  "to match --decoder-embed-dim"
              )
          if args.decoder_pretrained_embed and (
              args.decoder_pretrained_embed
              != args.encoder_pretrained_embed
          ):
              raise RuntimeError(
                  "--share-all-embeddings not compatible with "
                  "--decoder-pretrained-embed"
              )
          encoder_embed_tokens = build_embedding(
              dictionary=src_dict,
              embed_dim=args.encoder_embed_dim,
              path=args.encoder_pretrained_embed,
              freeze=args.encoder_freeze_embed,
          )
          decoder_embed_tokens = encoder_embed_tokens
          args.share_decoder_input_output_embed = True
      else:
          encoder_embed_tokens = build_embedding(
              dictionary=src_dict,
              embed_dim=args.encoder_embed_dim,
              path=args.encoder_pretrained_embed,
              freeze=args.encoder_freeze_embed,
          )
          decoder_embed_tokens = build_embedding(
              dictionary=tgt_dict,
              embed_dim=args.decoder_embed_dim,
              path=args.decoder_pretrained_embed,
              freeze=args.decoder_freeze_embed,
          )
  
      encoder = ClozeTransformerModel.build_encoder(
          args, src_dict, embed_tokens=encoder_embed_tokens
      )
      decoder = ClozeTransformerModel.build_decoder(
          args, src_dict, tgt_dict, embed_tokens=decoder_embed_tokens
      )
      return ClozeTransformerModel(task, encoder, decoder)
  
file_path: translate/pytorch_translate/research/rescore/cloze_transformer_model.py
imports: import torch
  from fairseq import utils
  from fairseq.models import register_model, register_model_architecture
  from pytorch_translate.transformer import base_architecture, build_embedding, TransformerDecoder, TransformerModel
label_desc: Use image node_id 1 for calling the ClozeTransformerModel obj's underlying member method code with example usage: obj.build_model(cls, args, task) and returns: ClozeTransformerModel