All Projects → weizhepei → BERT-NER

weizhepei / BERT-NER

Licence: MIT license
Using pre-trained BERT models for Chinese and English NER with 🤗Transformers

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to BERT-NER

Spark Nlp
State of the Art Natural Language Processing
Stars: ✭ 2,518 (+2108.77%)
Mutual labels:  transformers, named-entity-recognition, seq2seq
Cluener2020
CLUENER2020 中文细粒度命名实体识别 Fine Grained Named Entity Recognition
Stars: ✭ 689 (+504.39%)
Mutual labels:  named-entity-recognition, seq2seq
TorchBlocks
A PyTorch-based toolkit for natural language processing
Stars: ✭ 85 (-25.44%)
Mutual labels:  transformers, named-entity-recognition
eve-bot
EVE bot, a customer service chatbot to enhance virtual engagement for Twitter Apple Support
Stars: ✭ 31 (-72.81%)
Mutual labels:  transformers, named-entity-recognition
Pytorch-NLU
Pytorch-NLU,一个中文文本分类、序列标注工具包,支持中文长文本、短文本的多类、多标签分类任务,支持中文命名实体识别、词性标注、分词等序列标注任务。 Ptorch NLU, a Chinese text classification and sequence annotation toolkit, supports multi class and multi label classification tasks of Chinese long text and short text, and supports sequence annotation tasks such as Chinese named entity recognition, part of speech ta…
Stars: ✭ 151 (+32.46%)
Mutual labels:  transformers, named-entity-recognition
classy
classy is a simple-to-use library for building high-performance Machine Learning models in NLP.
Stars: ✭ 61 (-46.49%)
Mutual labels:  transformers, seq2seq
Kashgari
Kashgari is a production-level NLP Transfer learning framework built on top of tf.keras for text-labeling and text-classification, includes Word2Vec, BERT, and GPT2 Language Embedding.
Stars: ✭ 2,235 (+1860.53%)
Mutual labels:  named-entity-recognition, seq2seq
Simpletransformers
Transformers for Classification, NER, QA, Language Modelling, Language Generation, T5, Multi-Modal, and Conversational AI
Stars: ✭ 2,881 (+2427.19%)
Mutual labels:  transformers, named-entity-recognition
ChineseNER
中文NER的那些事儿
Stars: ✭ 241 (+111.4%)
Mutual labels:  chinese-ner, msra
deep-atrous-ner
Deep-Atrous-CNN-NER: Word level model for Named Entity Recognition
Stars: ✭ 35 (-69.3%)
Mutual labels:  named-entity-recognition, conll-2003
course-content-dl
NMA deep learning course
Stars: ✭ 537 (+371.05%)
Mutual labels:  transformers
TransCenter
This is the official implementation of TransCenter. The code and pretrained models are now available here: https://gitlab.inria.fr/yixu/TransCenter_official.
Stars: ✭ 82 (-28.07%)
Mutual labels:  transformers
iPerceive
Applying Common-Sense Reasoning to Multi-Modal Dense Video Captioning and Video Question Answering | Python3 | PyTorch | CNNs | Causality | Reasoning | LSTMs | Transformers | Multi-Head Self Attention | Published in IEEE Winter Conference on Applications of Computer Vision (WACV) 2021
Stars: ✭ 52 (-54.39%)
Mutual labels:  transformers
optimum
🏎️ Accelerate training and inference of 🤗 Transformers with easy to use hardware optimization tools
Stars: ✭ 567 (+397.37%)
Mutual labels:  transformers
deepfrog
An NLP-suite powered by deep learning
Stars: ✭ 16 (-85.96%)
Mutual labels:  transformers
nested-ner-tacl2020-flair
Implementation of Nested Named Entity Recognition using Flair
Stars: ✭ 23 (-79.82%)
Mutual labels:  named-entity-recognition
simple NER
simple rule based named entity recognition
Stars: ✭ 29 (-74.56%)
Mutual labels:  named-entity-recognition
FDDC
Named Entity Recognition & Relation Extraction 实体命名识别与关系分类
Stars: ✭ 29 (-74.56%)
Mutual labels:  named-entity-recognition
language-planner
Official Code for "Language Models as Zero-Shot Planners: Extracting Actionable Knowledge for Embodied Agents"
Stars: ✭ 84 (-26.32%)
Mutual labels:  transformers
fiction generator
Fiction generator with Tensorflow. 模仿王小波的风格的小说生成器
Stars: ✭ 27 (-76.32%)
Mutual labels:  seq2seq

BERT-NER

This project implements a solution to the "X" label issue (e.g., #148, #422) of NER task in Google's BERT paper, and is developed mostly based on lemonhu's work and bheinzerling's suggestion.

Dataset

Requirements

This repo was tested on Python 3.6+ and PyTorch 1.3.1. The main requirements are:

  • nltk
  • tqdm
  • pytorch >= 1.3.1
  • 🤗transformers == 2.2.2
  • tensorflow == 1.11.0 (Optional)

Note: The tensorflow library is only used for the conversion of pretrained models from TensorFlow to PyTorch.

Quick Start

  • Download and unzip the Chinese (English) NER model weights under experiments/msra(conll)/, then run:

    python build_dataset_tags.py --dataset=msra
    python interactive.py --dataset=msra

    to try it out and interact with the pretrained NER model.

Usage

  1. Get BERT model for PyTorch

    There are two ways to get the pretrained BERT model in a PyTorch dump for your experiments :

    • [Automatically] Download the specified pretrained BERT model provided by huggingface🤗

    • [Manually] Convert the TensorFlow checkpoint to a PyTorch dump

      • Download the Google's BERT pretrained models for Chinese (BERT-Base, Chinese) and English (BERT-Base, Cased). Then decompress them under pretrained_bert_models/bert-chinese-cased/ and pretrained_bert_models/bert-base-cased/ respectively. More pre-trained models are available here.

      • Execute the following command, convert the TensorFlow checkpoint to a PyTorch dump as huggingface suggests. Here is an example of the conversion process for a pretrained BERT-Base Cased model.

        export TF_BERT_MODEL_DIR=/full/path/to/cased_L-12_H-768_A-12
        export PT_BERT_MODEL_DIR=/full/path/to/pretrained_bert_models/bert-base-cased
         
        transformers bert \
          $TF_BERT_MODEL_DIR/bert_model.ckpt \
          $TF_BERT_MODEL_DIR/bert_config.json \
          $PT_BERT_MODEL_DIR/pytorch_model.bin
      • Copy the BERT parameters file bert_config.json and dictionary file vocab.txt to the directory $PT_BERT_MODEL_DIR.

        cp $TF_BERT_MODEL_DIR/bert_config.json $PT_BERT_MODEL_DIR/config.json
        cp $TF_BERT_MODEL_DIR/vocab.txt $PT_BERT_MODEL_DIR/vocab.txt
        
  2. Build dataset and tags

    if you use default parameters (using CONLL-2003 dataset as default) , just run

    python build_dataset_tags.py

    Or specify dataset (e.g., MSRA) and other parameters on the command line

    python build_dataset_tags.py --dataset=msra

    It will extract the sentences and tags from train_bio, test_bio and val_bio(if not provided, it will randomly sample 5% data from the train_bio to create val_bio). Then split them into train/val/test and save them in a convenient format for our model, and create a file tags.txt containing a collection of tags.

  3. Set experimental hyperparameters

    We created directories with the same name as datasets under the experiments directory. It contains a file params.json which sets the hyperparameters for the experiment. It looks like

    {
        "full_finetuning": true,
        "max_len": 180,
        "learning_rate": 5e-5,
        "weight_decay": 0.01,
        "clip_grad": 5,
    }

    For different datasets, you will need to create a new directory under experiments with params.json.

  4. Train and evaluate the model

    if you use default parameters (using CONLL-2003 dataset as default) , just run

    python train.py

    Or specify dataset (e.g., MSRA) and other parameters on the command line

    python train.py --dataset=msra

    A proper pretrained BERT model will be automatically chosen according to the language of the specified dataset. It will instantiate a model and train it on the training set following the hyper-parameters specified in params.json. It will also evaluate some metrics on the development set.

  5. Evaluation on the test set

    Once you've run many experiments and selected your best model and hyperparameters based on the performance on the development set, you can finally evaluate the performance of your model on the test set.

    if you use default parameters (using CONLL-2003 dataset as default) , just run

    python evaluate.py

    Or specify dataset (e.g., MSRA) and other parameters on the command line

    python evaluate.py --dataset=msra
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].