-
TensorFlow環境
官方requirements.txt要求環境版本tensorflow >= 1.11.0 # CPU Version of TensorFlow #tensorflow-gpu >= 1.11.0 # GPU version of TensorFlow.
本人實現代碼TensorFlow環境版本
tensorflow 1.15.0 tensorflow-estimator 1.15.1 tensorflow-gpu 1.15.0 python=3.6
-
數據集地址
#數據標注格式如下,合計三種實體:B-PER/B-LOC/B-ORG #每行得第一個是字,第二個是它的標簽,使用空格’ '分隔,請一定要使用空格。句與句之間使用空行划分。 海 O 釣 O 比 O 賽 O 地 O 點 O 在 O 廈 B-LOC 門 I-LOC 與 O 金 B-LOC 門 I-LOC 之 O 間 O 的 O 海 O 域 O 。 O
-
BERT-BiLSTM-CRF-NER源碼地址
-
代碼目錄
-
代碼運行流程
-
下載BERT-BiLSTM-CRF-NER源碼;
git clone https://github.com/macanv/BERT-BiLSTM-CRF-NER cd BERT-BiLSTM-CRF-NER/ python3 setup.py install
-
從google提供的BERT官方下載中文BERT預訓練模型chinese_L-12_H-768_A-12,將其放到BERT-BiLSTM-CRF-NER目錄下;
""" 其中 bert_model.ckpt開頭的文件是負責模型變量載入的 vocab.txt是訓練時中文文本采用的字典 bert_config.json是BERT在訓練時,可選調整的一些參數 """
-
train_helper參數解讀
#執行改命令 查看train_helper提供的相關參數 bert-base-ner-train -help #訓練的事例命名如下: bert-base-ner-train \ -data_dir {your dataset dir}\#訓練數據,驗證數據和測試數據的所在目錄路徑 -output_dir {training output dir}\#訓練完成后的指定輸出路徑 -init_checkpoint {Google BERT model dir}\#下載的谷歌BERT模型 -bert_config_file {bert_config.json under the Google BERT model dir} \# 谷歌BERT模型下面的bert_config.json -vocab_file {vocab.txt under the Google BERT model dir}#谷歌BERT模型下面的vocab.txt #本人實例 bert-base-ner-train \ -data_dir data \ -output_dir output \ -init_checkpoint chinese_L-12_H-768_A-12/bert_model.ckpt \ -bert_config_file chinese_L-12_H-768_A-12/bert_config.json \ -vocab_file chinese_L-12_H-768_A-12/vocab.txt \ -batch_size 8 #batch大小,對於普通8GB的GPU,最大batch大小只能是8,再大就會OOM #可以直接執行命令,也可以執行 python3 run.py#這種情況下參數一般都是默認的,可以到BERT-BiLSTM-CRF-NER/bert_base/train/train_helper.py去修改相關參數!
-
訓練成功截圖!
-