【Bert】(十五)命名实体识别–跑通代码

  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 代码位置

【Bert】(十五)命名实体识别--跑通代码
  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/

Original: https://blog.csdn.net/u013066730/article/details/123425591
Author: mjiansun
Title: 【Bert】(十五)命名实体识别–跑通代码

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/508803/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球