在bert上使用领域的数据集继续预训练

1、下载bert或者roberta的源码以及开源的预训练模型

https://github.com/brightmart/roberta_zh

2、准备好自己的领域数据

格式是:一行一句话,多个文本之间使用空行隔开

为了解决这个问题,很自然的想法就是词作为一个整体要么都 Mask 要么都不 Mask,这就是所谓的 Whole Word Masking。
这是一个很简单的想法,对于 BERT 的代码修改也非常少,只是修改一些 Mask 的那段代码。对于英文来说,分词是一个(相对)简单的问题。
哈工大与科大讯飞的论文对中文进行了分词,然后做了一些实验。

今天天气真好啊!
我和家人去公园游玩。

 

3、主要是使用两个函数:

1)生成bert模型使用的数据

python create_pretraining_data.py \
  --input_file=./our_text.txt \
  --output_file=./tmp/tf_examples.tfrecord \
  --vocab_file=/data/chinese_roberta_wwm_ext_L-12_H-768_A-12/vocab.txt \
  --do_lower_case=True \
  --max_seq_length=256 \
  --max_predictions_per_seq=20 \
  --masked_lm_prob=0.15 \
  --random_seed=12345 \
  --dupe_factor=5

 

2)这样就开始接着预训练了,记得修改原始的step_num等参数

python run_pretraining.py  \
--input_file=./tmp/tf_examples.tfrecord \
--output_dir=./tmp/pretraining_output \
--bert_config_file=/data/chinese_roberta_wwm_ext_L-12_H-768_A-12/bert_config.json \
--init_checkpoint=/data/chinese_roberta_wwm_ext_L-12_H-768_A-12/bert_model.ckpt \
--do_train=True \
--do_eval=True 

具体代码的细节,就去读源码去吧。

你可能感兴趣的:(NLP,python,tensorflow)