当前位置:   article > 正文

【Bert】(十五)命名实体识别--跑通代码_anconda安装bert 中文实体识别

anconda安装bert 中文实体识别

1. 环境安装

1.1 环境配置

1、安装anaconda环境

2、执行如下代码配置环境,不需要额外安装cuda和cudnn,如下的安装方式已经在环境中自动安装了cuda和cudnn,但只在conda叫bert的这个环境中生效,并不影响你原来安装的cuda和cudnn。

  1. conda create -n bert python=3.6
  2. conda activate bert
  3. conda install tensorflow-gpu==1.13.1

1.2 代码位置

2. 训练代码

选择的是将默认参数写在代码中,开始训练的之前,只需要修改下面的代码即可,在bert_base/train/train_helper.py中

  1. if os.name == 'nt': #windows path config
  2. bert_path = '{your BERT model path}'
  3. root_path = '{project path}'
  4. else: # linux path config
  5. bert_path = '{your BERT model path}'
  6. root_path = '{project path}'

执行训练命令(如果出现OOM,调小batchsize。 ):

  1. python run.py \
  2. -device_map 1 \
  3. -data_dir NERdata \
  4. -vocab_file chinese_L-12_H-768_A-12/vocab.txt \
  5. -bert_config_file chinese_L-12_H-768_A-12/bert_config.json \
  6. -init_checkpoint chinese_L-12_H-768_A-12/bert_model.ckpt \
  7. -max_seq_length 128 \
  8. -batch_size 16 \
  9. -learning_rate 2e-5 \
  10. -num_train_epochs 3.0 \
  11. -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。

  1. python run.py \
  2. -do_train \
  3. -do_eval \
  4. -device_map 1 \
  5. -data_dir NERdata \
  6. -vocab_file chinese_L-12_H-768_A-12/vocab.txt \
  7. -bert_config_file chinese_L-12_H-768_A-12/bert_config.json \
  8. -init_checkpoint chinese_L-12_H-768_A-12/bert_model.ckpt \
  9. -max_seq_length 128 \
  10. -batch_size 16 \
  11. -learning_rate 2e-5 \
  12. -num_train_epochs 3.0 \
  13. -output_dir ./output/

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号