GithubHelp home page GithubHelp logo

tchewik / bert_sequence_tagger Goto Github PK

View Code? Open in Web Editor NEW

This project forked from iinemo/bert_sequence_tagger

0.0 1.0 0.0 26 KB

Sequence tagger based on BERT

Python 58.63% Jupyter Notebook 41.37%

bert_sequence_tagger's Introduction

Description

BERT sequence tagger that accepts token list as an input (not BPE but any "general" tokenizer like NLTK or Standford) and produces tagged results in IOB format.

Training BERT model has many caveats that include but not limited to:

  • Proper masking of the input.
  • Proper padding of input.
  • Loss masking (masking loss of the padded tokens and loss of the BPE suffixes).
  • Adding proper special tokens like [CLS], [SEP] to the beginning and an end of a sequence.
  • Annealing of the learning rate, as well as properly handling the best models.
  • Proper calculation of the validation / training loss (taking into account masked tokens and masked loss elements).

Pytorch_transformers provides a good pytorch implementation of BertForTokenClassification (not wihtout flaws), however, it lacks code for proper trainig of sequence tagging models. Noticable effort is required to convert a tokenized text into an input suitable for BERT, with which you can achieve SOTA.

This library does this work for you: it takes a tokenized input, performs bpe tokenization, padding, preparations, and all other work to prepare input for BERT. It also provides a trainer that can achieve a good performance for BERT models.

Example

from sequence_tagger_bert import SequenceTaggerBert, ModelTrainerBert
from flair.datasets import ColumnCorpus

data_folder = '../data/conll2003'

corpus = ColumnCorpus(data_folder, 
                      {0 : 'text', 3 : 'ner'},
                      train_file='eng.train.txt',
                      test_file='eng.testb.txt',
                      dev_file='eng.testa.txt')

bpe_tokenizer = BertTokenizer.from_pretrained('bert-base-cased', 
                                              do_lower_case=False)

model, optimizer = create_model_optimizer(tag2idx, 
                                          full_finetuning=True, 
                                          base_lr=5e-5,
                                          bert_model='bert-base-cased')

bert_sequence_tagger's People

Contributors

iinemo avatar

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.