[英]How to use fine-tuned BERT model for sentence encoding?
我按照此处的脚本在我自己的数据集上微调了 BERT 基础 model:
https://github.com/cedrickchee/pytorch-pretrained-BERT/tree/master/examples/lm_finetuning
我将 model 保存为.pt
文件,现在我想将其用于句子相似性任务。 不幸的是,我不清楚如何加载经过微调的 model。 我尝试了以下方法:
model = BertModel.from_pretrained('trained_model.pt')
model.eval()
这行不通。 它说:
ReadError: not a gzip file
显然,使用from_pretrained
方法加载.pt
文件是不可能的。 有谁可以帮我离开这里吗? 非常感谢:! :)
编辑:我将 model 保存在 s3 存储桶中,如下所示:
# Convert model to buffer
buffer = io.BytesIO()
torch.save(model, buffer)
# Save in s3 bucket
output_model_file = output_folder + "trained_model.pt"
s3_.put_object(Bucket="power-plant-embeddings", Key=output_model_file, Body=buffer.getvalue())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.