def build_transformer_model(config_path=None, checkpoint_path=None, model='bert', application='encoder', return_keras_model=True, **kwargs):
    '根据配置文件构建模型，可选加载checkpoint权重\n    '
    configs = {}
    if (config_path is not None):
        configs.update(json.load(open(config_path)))
    configs.update(kwargs)
    if ('max_position' not in configs):
        configs['max_position'] = configs.get('max_position_embeddings', 512)
    if ('dropout_rate' not in configs):
        configs['dropout_rate'] = configs.get('hidden_dropout_prob')
    if ('segment_vocab_size' not in configs):
        configs['segment_vocab_size'] = configs.get('type_vocab_size', 2)
    models = {'bert': BERT, 'albert': ALBERT, 'albert_unshared': ALBERT_Unshared, 'roberta': BERT, 'nezha': NEZHA, 'electra': ELECTRA, 'gpt': GPT, 'gpt2': GPT2, 'gpt2_ml': GPT2_ML, 't5': T5, 't5_encoder': T5_Encoder, 't5_decoder': T5_Decoder, 't5.1.0': T5, 't5.1.0_encoder': T5_Encoder, 't5.1.0_decoder': T5_Decoder, 't5.1.1': T5, 't5.1.1_encoder': T5_Encoder, 't5.1.1_decoder': T5_Decoder}
    if is_string(model):
        model = model.lower()
        MODEL = models[model]
    else:
        MODEL = model
    application = application.lower()
    if ((application in ['lm', 'unilm']) and (model in ['electra', 't5'])):
        raise ValueError(('"%s" model can not be used as "%s" application.\n' % (model, application)))
    if (application == 'lm'):
        MODEL = extend_with_language_model(MODEL)
    elif (application == 'unilm'):
        MODEL = extend_with_unified_language_model(MODEL)
    if model.startswith('t5.1.1'):
        configs['version'] = 't5.1.1'
    transformer = MODEL(**configs)
    transformer.build(**configs)
    if (checkpoint_path is not None):
        transformer.load_weights_from_checkpoint(checkpoint_path)
    if return_keras_model:
        return transformer.model
    else:
        return transformer
根据配置文件构建模型，可选加载checkpoint权重
def build_transformer_model(config_path=None, checkpoint_path=None, model='bert', application='encoder', return_keras_model=True, **kwargs):
    '\n    '
    configs = {}
    if (config_path is not None):
        configs.update(json.load(open(config_path)))
    configs.update(kwargs)
    if ('max_position' not in configs):
        configs['max_position'] = configs.get('max_position_embeddings', 512)
    if ('dropout_rate' not in configs):
        configs['dropout_rate'] = configs.get('hidden_dropout_prob')
    if ('segment_vocab_size' not in configs):
        configs['segment_vocab_size'] = configs.get('type_vocab_size', 2)
    models = {'bert': BERT, 'albert': ALBERT, 'albert_unshared': ALBERT_Unshared, 'roberta': BERT, 'nezha': NEZHA, 'electra': ELECTRA, 'gpt': GPT, 'gpt2': GPT2, 'gpt2_ml': GPT2_ML, 't5': T5, 't5_encoder': T5_Encoder, 't5_decoder': T5_Decoder, 't5.1.0': T5, 't5.1.0_encoder': T5_Encoder, 't5.1.0_decoder': T5_Decoder, 't5.1.1': T5, 't5.1.1_encoder': T5_Encoder, 't5.1.1_decoder': T5_Decoder}
    if is_string(model):
        model = model.lower()
        MODEL = models[model]
    else:
        MODEL = model
    application = application.lower()
    if ((application in ['lm', 'unilm']) and (model in ['electra', 't5'])):
        raise ValueError(('"%s" model can not be used as "%s" application.\n' % (model, application)))
    if (application == 'lm'):
        MODEL = extend_with_language_model(MODEL)
    elif (application == 'unilm'):
        MODEL = extend_with_unified_language_model(MODEL)
    if model.startswith('t5.1.1'):
        configs['version'] = 't5.1.1'
    transformer = MODEL(**configs)
    transformer.build(**configs)
    if (checkpoint_path is not None):
        transformer.load_weights_from_checkpoint(checkpoint_path)
    if return_keras_model:
        return transformer.model
    else:
        return transformer