1、安装相关模块
(1)tensorflow
pip install tensorflow==2.4 -i https://pypi.douban.com/simple
(2)pytorch
(3) pytorch_transformers
pip install pytorch_transformers -i https://pypi.douban.com/simple
2、下载bert预训练模型
https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip
2、进入转换代码目录
cd C:\Program Files\Anaconda3\envs\torch\Lib\site-packages\pytorch_transformers
3、执行命令
python convert_tf_checkpoint_to_pytorch.py --tf_checkpoint_path=C:/chinese_L-12_H-768_A-12/bert_model.ckpt --bert_config_file=C:/chinese_L-12_H-768_A-12/bert_config.json --pytorch_dump_path=D:/transformers/chinese_L-12_H-768_A-12/pytorch_model.bin
4、拷贝配置文件和词典文件
拷贝bert_config.json 和 vocab.txt 两个文件到pytorch_model.bin 文件所在目录
将bert_config.json 重命名为config.json