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

2. 训练代码

选择的是将默认参数写在代码中,开始训练的之前,只需要修改下面的代码即可,在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/

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值