@classmethod
def build_model(cls, args, task):
    'Build a new model instance.'
    base_architecture(args)
    if (not hasattr(args, 'max_source_positions')):
        args.max_source_positions = DEFAULT_MAX_SOURCE_POSITIONS
    if (not hasattr(args, 'max_target_positions')):
        args.max_target_positions = DEFAULT_MAX_TARGET_POSITIONS
    (src_dict, tgt_dict) = (task.source_dictionary, task.target_dictionary)
    if (len(task.datasets) > 0):
        src_berttokenizer = next(iter(task.datasets.values())).berttokenizer
    else:
        src_berttokenizer = BertTokenizer.from_pretrained(args.bert_model_name)

    def build_embedding(dictionary, embed_dim, path=None):
        num_embeddings = len(dictionary)
        padding_idx = dictionary.pad()
        emb = Embedding(num_embeddings, embed_dim, padding_idx)
        if path:
            embed_dict = utils.parse_embedding(path)
            utils.load_embedding(embed_dict, dictionary, emb)
        return emb
    if args.share_all_embeddings:
        if (src_dict != tgt_dict):
            raise ValueError('--share-all-embeddings requires a joined dictionary')
        if (args.encoder_embed_dim != args.decoder_embed_dim):
            raise ValueError('--share-all-embeddings requires --encoder-embed-dim to match --decoder-embed-dim')
        if (args.decoder_embed_path and (args.decoder_embed_path != args.encoder_embed_path)):
            raise ValueError('--share-all-embeddings not compatible with --decoder-embed-path')
        encoder_embed_tokens = build_embedding(src_dict, args.encoder_embed_dim, args.encoder_embed_path)
        decoder_embed_tokens = encoder_embed_tokens
        args.share_decoder_input_output_embed = True
    else:
        encoder_embed_tokens = build_embedding(src_dict, args.encoder_embed_dim, args.encoder_embed_path)
        decoder_embed_tokens = build_embedding(tgt_dict, args.decoder_embed_dim, args.decoder_embed_path)
    bertencoder = BertModel.from_pretrained(args.bert_model_name)
    args.bert_out_dim = bertencoder.hidden_size
    encoder = cls.build_encoder(args, src_dict, encoder_embed_tokens)
    decoder = cls.build_decoder(args, tgt_dict, decoder_embed_tokens)
    return TransformerS2Model(encoder, decoder, bertencoder, src_berttokenizer, args.mask_cls_sep, args)
Build a new model instance.
@classmethod
def build_model(cls, args, task):
    
    base_architecture(args)
    if (not hasattr(args, 'max_source_positions')):
        args.max_source_positions = DEFAULT_MAX_SOURCE_POSITIONS
    if (not hasattr(args, 'max_target_positions')):
        args.max_target_positions = DEFAULT_MAX_TARGET_POSITIONS
    (src_dict, tgt_dict) = (task.source_dictionary, task.target_dictionary)
    if (len(task.datasets) > 0):
        src_berttokenizer = next(iter(task.datasets.values())).berttokenizer
    else:
        src_berttokenizer = BertTokenizer.from_pretrained(args.bert_model_name)

    def build_embedding(dictionary, embed_dim, path=None):
        num_embeddings = len(dictionary)
        padding_idx = dictionary.pad()
        emb = Embedding(num_embeddings, embed_dim, padding_idx)
        if path:
            embed_dict = utils.parse_embedding(path)
            utils.load_embedding(embed_dict, dictionary, emb)
        return emb
    if args.share_all_embeddings:
        if (src_dict != tgt_dict):
            raise ValueError('--share-all-embeddings requires a joined dictionary')
        if (args.encoder_embed_dim != args.decoder_embed_dim):
            raise ValueError('--share-all-embeddings requires --encoder-embed-dim to match --decoder-embed-dim')
        if (args.decoder_embed_path and (args.decoder_embed_path != args.encoder_embed_path)):
            raise ValueError('--share-all-embeddings not compatible with --decoder-embed-path')
        encoder_embed_tokens = build_embedding(src_dict, args.encoder_embed_dim, args.encoder_embed_path)
        decoder_embed_tokens = encoder_embed_tokens
        args.share_decoder_input_output_embed = True
    else:
        encoder_embed_tokens = build_embedding(src_dict, args.encoder_embed_dim, args.encoder_embed_path)
        decoder_embed_tokens = build_embedding(tgt_dict, args.decoder_embed_dim, args.decoder_embed_path)
    bertencoder = BertModel.from_pretrained(args.bert_model_name)
    args.bert_out_dim = bertencoder.hidden_size
    encoder = cls.build_encoder(args, src_dict, encoder_embed_tokens)
    decoder = cls.build_decoder(args, tgt_dict, decoder_embed_tokens)
    return TransformerS2Model(encoder, decoder, bertencoder, src_berttokenizer, args.mask_cls_sep, args)