Bert模型-demo启动

193 阅读1分钟

1. 环境

python 3.6.9

pip 21.3.1

TensorFlow 1.11.0

开发工具:pycharm 社区版 23.3.2

如下:

image.png

2.资源准备

1) 开源项目 bert-master

官网网址: github.com/google-rese…

clone 和 download zip 都可。

image.png

  1. 模型和语料

模型:只下载了bert-base类型的 中文预训练模型和英文(大小写匹配cased,大小写不匹配uncased)预训练模型。

large的太大了。

image.png

语料:

image.png

以上都是官网提供的语料,MRPC是uncased模型常用语料。

3. 启动配置

image.png


--task_name=MRPC
--do_train=true
--do_eval=true
--data_dir=E:/py_workspace/BERT/GLUE/glue_data/MRPC
--vocab_file=../GLUE/BERT_BASE_DIR/uncased_L-12_H-768_A-12/vocab.txt
--bert_config_file=../GLUE/BERT_BASE_DIR/uncased_L-12_H-768_A-12/bert_config.json
--init_checkpoint=../GLUE/BERT_BASE_DIR/uncased_L-12_H-768_A-12/bert_model.ckpt
--max_seq_length=128
--train_batch_size=8
--learning_rate=2e-5
--num_train_epochs=3.0
--output_dir=../mrpc_output/

data_dir
vocab_file
bert_config_file
init_checkpoint
这四个根据自己文件地址进行配置。

4.结果

没有TPU, 启动都cpu直接拉满,独显的GPU没占用,就很离谱。MPRC跑了3个小时左右,下面是结果。

image.png