Giter VIP home page Giter VIP logo

bert-chinesener's Introduction

BERT Chinese NER

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

参考:https://github.com/yanwii/ChineseNER https://github.com/macanv/BERT-BiLSTM-CRF-NER

下载bert预训练模型

wget -c https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip

放到根目录 bert_model

用法

# 训练
python3 model.py -e train


# 预测
python3 model.py -e predict

介绍

bert 模型的加载和使用

def bert_layer(self):
    # 加载bert配置文件
    bert_config = modeling.BertConfig.from_json_file(ARGS.bert_config)

    # 创建bert模型 
    model = modeling.BertModel(
        config=bert_config,
        is_training=self.is_training,
        input_ids=self.input_ids,
        input_mask=self.input_mask,
        token_type_ids=self.segment_ids,
        use_one_hot_embeddings=False
    )
    # 加载词向量
    self.embedded = model.get_sequence_output()
    self.model_inputs = tf.nn.dropout(
        self.embedded, self.dropout
    )

bert 优化器

self.train_op = create_optimizer(
    self.loss, self.learning_rate, num_train_steps, num_warmup_steps, False
)

例子

> 金树良先生,董事,硕士。现任北方国际信托股份有限公司总经济师。曾任职于北京大学经济学院国际经济系。1992年7月起历任海南省证券公司副总裁、北京华宇世纪投资有限公司副总裁、昆仑证券有限责任公司总裁、北方国际信托股份有限公司资产管理部总经理及公司总经理助理兼资产管理部总经理、渤海财产保险股份有限公司常务副总经理及总经理、北方国际信托股份有限公司总经理助理。
>   [
        {
          "begin": 14,
          "end": 26,
          "entity": "北方国际信托股份有限公司",
          "type": "ORG"
        },
        {
          "begin": 70,
          "end": 82,
          "entity": "北京华宇世纪投资有限公司",
          "type": "ORG"
        },
        {
          "begin": 99,
          "end": 111,
          "entity": "北方国际信托股份有限公司",
          "type": "ORG"
        },
        {
          "begin": 160,
          "end": 172,
          "entity": "北方国际信托股份有限公司",
          "type": "ORG"
        },
        {
          "begin": 0,
          "end": 3,
          "entity": "金树良",
          "type": "PER"
        }
    ]

bert-chinesener's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.