docstr: Build a new multilingual model instance.
docstr_tok: ["Build","a","new","multilingual","model","instance","."]
code: def build_model_multilingual(cls, args, task):
      """Build a new multilingual model instance."""
      encoders = []
      for lang in args.multiling_encoder_lang:
          d = task.source_dictionaries.get(lang, None)
          if d is not None:
              encoder_embed_tokens = Embedding(
                  num_embeddings=len(d),
                  embedding_dim=args.encoder_embed_dim,
                  padding_idx=d.pad(),
                  freeze_embed=args.encoder_freeze_embed,
                  normalize_embed=args.encoder_normalize_embed,
              )
              pytorch_translate_utils.load_embedding(
                  embedding=encoder_embed_tokens,
                  dictionary=d,
                  pretrained_embed=args.encoder_pretrained_embed,
              )
              encoders.append(
                  RNNModel.build_encoder(
                      args, d, embed_tokens=encoder_embed_tokens
                  )
              )
          else:
              encoders.append(None)
      encoder = MultilingualEncoder(
          task.source_dictionary,
          encoders,
          hidden_dim=args.encoder_hidden_dim,
          num_layers=args.encoder_layers,
          embed_dim=args.encoder_embed_dim,
          rescale_grads=args.multiling_rescale_grads,
      )
      decoders = []
      for lang in args.multiling_decoder_lang:
          d = task.target_dictionaries.get(lang, None)
          if d is not None:
              decoder_embed_tokens = Embedding(
                  num_embeddings=len(d),
                  embedding_dim=args.decoder_embed_dim,
                  padding_idx=d.pad(),
                  freeze_embed=args.decoder_freeze_embed,
              )
  
              pytorch_translate_utils.load_embedding(
                  embedding=decoder_embed_tokens,
                  dictionary=d,
                  pretrained_embed=args.decoder_pretrained_embed,
              )
              decoders.append(
                  RNNModel.build_decoder(
                      args, None, d, embed_tokens=decoder_embed_tokens
                  )
              )
          else:
              decoders.append(None)
      decoder = MultilingualDecoder(
          task.target_dictionary,
          decoders,
          hidden_dim=args.encoder_hidden_dim,
          rescale_grads=args.multiling_rescale_grads,
      )
      return cls(task, encoder, decoder)
  
imports: import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.onnx.operators
  from fairseq import options, utils
  from fairseq.models import FairseqEncoder, FairseqEncoderDecoderModel, register_model, register_model_architecture
  from fairseq.modules import AdaptiveSoftmax
  from pytorch_translate import attention, rnn_cell, utils, vocab_reduction
  from pytorch_translate.common_layers import ContextEmbedding, DecoderWithOutputProjection, Embedding, Linear, RNNLayer, VariableTracker
  from pytorch_translate.data import data
  from pytorch_translate.multi_model import MultiDecoder, MultiEncoder
  from pytorch_translate.multilingual import MultilingualDecoder, MultilingualEncoder
  from pytorch_translate.ngram import NGramDecoder
  from pytorch_translate.semi_supervised import SemiSupervisedModel
  from pytorch_translate.utils import maybe_cat, maybe_cuda, torch_find
  from torch.nn.utils.rnn import pack_padded_sequence, PackedSequence, pad_packed_sequence
label_desc: Use image node_id 9 for calling the RNNModel obj's underlying member method code with example usage: obj.build_model_multilingual(cls, args, task) and returns: cls