赞
踩
1、安装anaconda环境
2、执行如下代码配置环境,不需要额外安装cuda和cudnn,如下的安装方式已经在环境中自动安装了cuda和cudnn,但只在conda叫bert的这个环境中生效,并不影响你原来安装的cuda和cudnn。
- conda create -n bert python=3.6
- conda activate bert
- conda install tensorflow-gpu==1.13.1
选择的是将默认参数写在代码中,开始训练的之前,只需要修改下面的代码即可,在bert_base/train/train_helper.py中
- if os.name == 'nt': #windows path config
- bert_path = '{your BERT model path}'
- root_path = '{project path}'
- else: # linux path config
- bert_path = '{your BERT model path}'
- root_path = '{project path}'
执行训练命令(如果出现OOM,调小batchsize。 ):
- python run.py \
- -device_map 1 \
- -data_dir NERdata \
- -vocab_file chinese_L-12_H-768_A-12/vocab.txt \
- -bert_config_file chinese_L-12_H-768_A-12/bert_config.json \
- -init_checkpoint chinese_L-12_H-768_A-12/bert_model.ckpt \
- -max_seq_length 128 \
- -batch_size 16 \
- -learning_rate 2e-5 \
- -num_train_epochs 3.0 \
- -output_dir ./output/
group2.add_argument('-do_train', action='store_false', default=True, help='Whether to run training.') group2.add_argument('-do_eval', action='store_false', default=True, help='Whether to run eval on the dev set.') group2.add_argument('-do_predict', action='store_false', default=True, help='Whether to run the predict in inference mode on the test set.')这三个的意思是只要你开了,不用赋值,那么他就会使用action中的false值。
例如测试代码,开了-do_train和-do_eval就表示这2个不执行,只执行predict。
- python run.py \
- -do_train \
- -do_eval \
- -device_map 1 \
- -data_dir NERdata \
- -vocab_file chinese_L-12_H-768_A-12/vocab.txt \
- -bert_config_file chinese_L-12_H-768_A-12/bert_config.json \
- -init_checkpoint chinese_L-12_H-768_A-12/bert_model.ckpt \
- -max_seq_length 128 \
- -batch_size 16 \
- -learning_rate 2e-5 \
- -num_train_epochs 3.0 \
- -output_dir ./output/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。