基于BERT预训练的中文命名实体识别TensorFlow实现

2020-06-29

基于BERT预训练的中文命名实体识别TensorFlow实现

项目简介

本项目提供了一个基于BERT预训练模型的中文命名实体识别(NER)的TensorFlow实现。通过使用BERT模型进行预训练,结合BiLSTM-CRF结构,实现了高效的中文命名实体识别任务。

功能特点

  • BERT预训练模型:利用Google的BERT预训练模型进行特征提取,提升模型性能。
  • BiLSTM-CRF结构:结合双向长短期记忆网络(BiLSTM)和条件随机场(CRF),提高命名实体识别的准确性。
  • 支持自定义数据集:用户可以根据自己的需求,使用自定义数据集进行训练和测试。
  • 模型服务部署:支持将训练好的模型部署为服务,方便实际应用中的调用。

使用说明

安装依赖

  1. 使用pip安装所需的Python包:
    pip install bert-base==0.0.7 -i https://pypi.python.org/simple
    

    或者通过源代码安装:

    git clone https://github.com/macanv/BERT-BiLSTM-CRF-NER
    cd BERT-BiLSTM-CRF-NER/
    python3 setup.py install
    

训练模型

  1. 准备数据集:将训练数据、验证数据和测试数据分别命名为train.txtdev.txttest.txt,并放置在同一目录下。
  2. 使用以下命令进行模型训练:
    bert-base-ner-train \
      -data_dir [your dataset dir] \
      -output_dir [training output dir] \
      -init_checkpoint [Google BERT model dir] \
      -bert_config_file [bert_config.json under the Google BERT model dir] \
      -vocab_file [vocab.txt under the Google BERT model dir]
    

模型部署

  1. 使用以下命令启动模型服务:
    bert-base-serving-start \
      -model_dir [your trained model dir] \
      -bert_model_dir [Google BERT model dir] \
      -mode NER
    

参考资料

贡献

欢迎大家分享训练的模型或者新的方法和数据,共同提升模型的性能和应用范围。

许可证

本项目遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

下载链接

基于BERT预训练的中文命名实体识别TensorFlow实现