项目作者: Ma-Dan

项目描述 :
Tensorflow solution of NER task Using BiLSTM-CRF model with CMU/Google XLNet
高级语言: Python
项目地址: git://github.com/Ma-Dan/XLNet-ChineseNER.git
创建时间: 2019-09-17T10:08:25Z
项目社区:https://github.com/Ma-Dan/XLNet-ChineseNER

开源协议:

下载


XLNet Chinese NER

基于Bi-LSTM + CRF 的中文机构名、人名、地名识别,MSRA NER语料,BIO标注

CMU XLNet

参考资料:

https://github.com/yanwii/ChineseNER

https://github.com/macanv/BERT-BiLSTM-CRF-NER

https://github.com/zihangdai/xlnet

https://github.com/ymcui/Chinese-PreTrained-XLNet

下载xlnet中文预训练模型

  1. 参考 https://github.com/ymcui/Chinese-PreTrained-XLNet
  2. 放到根目录 **chinese_xlnet_base_L-12_H-768_A-12**

用法

  1. # 训练
  2. python3 model.py --entry train
  3. # 预测
  4. python3 model.py --entry predict

介绍

xlnet 模型的加载和使用

  1. def xlnet_layer(self):
  2. # 加载bert配置文件
  3. xlnet_config = xlnet.XLNetConfig(json_path = FLAGS.xlnet_config)
  4. run_config = xlnet.create_run_config(self.is_training, True, FLAGS)
  5. # 创建bert模型 
  6. xlnet_model = xlnet.XLNetModel(
  7. xlnet_config = xlnet_config,
  8. run_config = run_config,
  9. input_ids = self.input_ids,
  10. seg_ids = self.segment_ids,
  11. input_mask = self.input_mask)
  12. # 加载词向量
  13. self.embedded = xlnet_model.get_sequence_output()
  14. self.model_inputs = tf.nn.dropout(
  15. self.embedded, self.dropout
  16. )

xlnet 优化器

  1. self.train_op, self.learning_rate, _ = model_utils.get_train_op(FLAGS, self.loss)