赞
踩
在复现代码RSTNet[1]时,其中bert模型训练需要从hugging face上下载预训练参数,但由于网络原因,始终无法连接上hugging face。因此,采用离线的方式进行。步骤如下:
1.进入Hugging Face – The AI community building the future. (需要梯子)在左上角检索bert-base-uncased,点击。
2.来到这个页面后,点击Files and versions。
3.下载文件,红色圈中部分全下,剩下的是对应不同框架的模型,例如本人是pytorch的代码,就下载了pytorch_model.bin(图中打勾的地方)。
4.全部下载之后,将其放入一个文件夹中,放置进入代码根目录,如下图(bert_base_uncased文件夹)。
5.接下来修改models/rstnet中的language_model.py文件中第42行:
self.language_model = BertModel.from_pretrained('bert-base-uncased', return_dict=True)
将其改为
self.language_model = BertModel.from_pretrained(BERT_PATH)
其中BERT_PATH为我们所命名文件夹的路径例如:
BERT_PATH = './bert_base_uncased' (表示linux下当前目录下的bert_base_uncased,请注意,此时需要在代码根目录运行指令python train_language.py --exp_name bert_language --batch_size 50 --features_path /path/to/features --annotation_folder /path/to/annotations)
然后就可以正常运行了
引用:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。