1. 环境安装
1.1 环境配置
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
1.2 代码位置
2. 训练代码
执行训练命令(如果出现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/
例如测试代码,开了-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/