本文整理匯總了Python中pytorch_pretrained_bert.modeling.BertForPreTraining方法的典型用法代碼示例。如果您正苦於以下問題:Python modeling.BertForPreTraining方法的具體用法?Python modeling.BertForPreTraining怎麽用?Python modeling.BertForPreTraining使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pytorch_pretrained_bert.modeling
的用法示例。
在下文中一共展示了modeling.BertForPreTraining方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: convert_tf_checkpoint_to_pytorch
# 需要導入模塊: from pytorch_pretrained_bert import modeling [as 別名]
# 或者: from pytorch_pretrained_bert.modeling import BertForPreTraining [as 別名]
def convert_tf_checkpoint_to_pytorch(tf_checkpoint_path, bert_config_file, pytorch_dump_path):
# Initialise PyTorch model
config = BertConfig.from_json_file(bert_config_file)
print("Building PyTorch model from configuration: {}".format(str(config)))
model = BertForPreTraining(config)
# Load weights from tf checkpoint
load_tf_weights_in_bert(model, tf_checkpoint_path)
# Save pytorch-model
print("Save PyTorch model to {}".format(pytorch_dump_path))
torch.save(model.state_dict(), pytorch_dump_path)
開發者ID:649453932,項目名稱:Bert-Chinese-Text-Classification-Pytorch,代碼行數:14,代碼來源:convert_tf_checkpoint_to_pytorch.py