All Projects → yg211 → bert_nli

yg211 / bert_nli

Licence: other
A Natural Language Inference (NLI) model based on Transformers (BERT and ALBERT)

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to bert nli

bert in a flask
A dockerized flask API, serving ALBERT and BERT predictions using TensorFlow 2.0.
Stars: ✭ 32 (-67.01%)
Mutual labels:  albert, bert
hard-label-attack
Natural Language Attacks in a Hard Label Black Box Setting.
Stars: ✭ 26 (-73.2%)
Mutual labels:  bert, nli
Albert zh
A LITE BERT FOR SELF-SUPERVISED LEARNING OF LANGUAGE REPRESENTATIONS, 海量中文预训练ALBERT模型
Stars: ✭ 3,500 (+3508.25%)
Mutual labels:  albert, bert
MobileQA
离线端阅读理解应用 QA for mobile, Android & iPhone
Stars: ✭ 49 (-49.48%)
Mutual labels:  albert, bert
Transformer-QG-on-SQuAD
Implement Question Generator with SOTA pre-trained Language Models (RoBERTa, BERT, GPT, BART, T5, etc.)
Stars: ✭ 28 (-71.13%)
Mutual labels:  albert, bert
keras-bert-ner
Keras solution of Chinese NER task using BiLSTM-CRF/BiGRU-CRF/IDCNN-CRF model with Pretrained Language Model: supporting BERT/RoBERTa/ALBERT
Stars: ✭ 7 (-92.78%)
Mutual labels:  albert, bert
Clue
中文语言理解测评基准 Chinese Language Understanding Evaluation Benchmark: datasets, baselines, pre-trained models, corpus and leaderboard
Stars: ✭ 2,425 (+2400%)
Mutual labels:  albert, bert
classifier multi label
multi-label,classifier,text classification,多标签文本分类,文本分类,BERT,ALBERT,multi-label-classification
Stars: ✭ 127 (+30.93%)
Mutual labels:  albert, bert
NLP-paper
🎨 🎨NLP 自然语言处理教程 🎨🎨 https://dataxujing.github.io/NLP-paper/
Stars: ✭ 23 (-76.29%)
Mutual labels:  albert, bert
Fill-the-GAP
[ACL-WS] 4th place solution to gendered pronoun resolution challenge on Kaggle
Stars: ✭ 13 (-86.6%)
Mutual labels:  natural-language-inference, bert
ALBERT-Pytorch
Pytorch Implementation of ALBERT(A Lite BERT for Self-supervised Learning of Language Representations)
Stars: ✭ 214 (+120.62%)
Mutual labels:  albert, bert
banglabert
This repository contains the official release of the model "BanglaBERT" and associated downstream finetuning code and datasets introduced in the paper titled "BanglaBERT: Language Model Pretraining and Benchmarks for Low-Resource Language Understanding Evaluation in Bangla" accpeted in Findings of the Annual Conference of the North American Chap…
Stars: ✭ 186 (+91.75%)
Mutual labels:  natural-language-inference, bert
Medi-CoQA
Conversational Question Answering on Clinical Text
Stars: ✭ 22 (-77.32%)
Mutual labels:  albert, bert
CLUE pytorch
CLUE baseline pytorch CLUE的pytorch版本基线
Stars: ✭ 72 (-25.77%)
Mutual labels:  albert, bert
tfbert
基于tensorflow1.x的预训练模型调用,支持单机多卡、梯度累积,XLA加速,混合精度。可灵活训练、验证、预测。
Stars: ✭ 54 (-44.33%)
Mutual labels:  albert, bert
Chineseglue
Language Understanding Evaluation benchmark for Chinese: datasets, baselines, pre-trained models,corpus and leaderboard
Stars: ✭ 1,548 (+1495.88%)
Mutual labels:  albert, bert
Nlp Recipes
Natural Language Processing Best Practices & Examples
Stars: ✭ 5,783 (+5861.86%)
Mutual labels:  natural-language-inference, nli
classifier multi label seq2seq attention
multi-label,classifier,text classification,多标签文本分类,文本分类,BERT,ALBERT,multi-label-classification,seq2seq,attention,beam search
Stars: ✭ 26 (-73.2%)
Mutual labels:  albert, bert
Spark Nlp
State of the Art Natural Language Processing
Stars: ✭ 2,518 (+2495.88%)
Mutual labels:  albert, bert
tensorflow-ml-nlp-tf2
텐서플로2와 머신러닝으로 시작하는 자연어처리 (로지스틱회귀부터 BERT와 GPT3까지) 실습자료
Stars: ✭ 245 (+152.58%)
Mutual labels:  bert, nli

BERT-based NLI model

This project includes a natural language inference (NLI) model, developed by fine-tuning Transformers on the SNLI, MultiNLI and Hans datasets. This project has been used to develop our paper Adapting by Pruning: A Case Study on BERT(appendix). Please cite this paper when you use this project.

Highlighted Features

  • Models based on BERT-(base, large) and ALBERT-(base,large)
  • Implemented using PyTorch (1.5.0)
  • Low memory requirements: Using mixed-precision (nvidia apex) and checkpoint to reduce the GPU memory consumption; training the bert/albert-large model only requires around 6GB GPU memory (with batch size 8).
  • Easy inerface: A user-friendly interface is provided to use the trained models
  • All source code: All source code for training and testing the models is provided

Contact person: Yang Gao, [email protected]

https://sites.google.com/site/yanggaoalex/home

Don't hesitate to send me an e-mail or report an issue, if something is broken or if you have further questions.

Use the trained NLI model

  • The pretrained models are downloaded to output/ (after you run get_data.py in datasets/)
  • An example is presented in example.py:
from bert_nli import BertNLIModel

model = BertNLIModel('output/bert-base.state_dict')
sent_pairs = [('The lecturer committed plagiarism.','He was promoted.')]
label, _= model(sent_pairs)
print(label)

The output of the above example is:

['contradiction']

How to set up

  • Python3.7
  • Install all packages in requirement.txt.
pip3 install -r requirements.txt
  • Download the SNLI and MultiNLI data as well as the trained model with the commands below
cd datasets/
python get_data.py
  • (Optional) Our code supports the use of the Hans dataset to train the model, in order to prevent the BERT model from exploiting spurious features to make NLI predictions. To use the Hans dataset, download heuristics_train_set.txt and heuristics_evaluation_set.txt from here, and put them to datasets/Hans/. During training/test, add argument --hans 1.
  • (Optional) To use mixed precision training (nvidia apex), run the code below:
git clone https://github.com/NVIDIA/apex
cd apex
pip install -v --no-cache-dir --global-option="--cpp_ext" --global-option="--cuda_ext" ./
  • All code is tested on a desktop with a single nVidia RTX 2080 card (8GB memory), running Python 3.7 on Ubuntu 18.04 LTS.

Train NLI models

  • Run train.py and specify what Transformer model you would like to fine tune:
python train.py --bert_type bert-large --check_point 1

Option "--check_point 1" means that we will use the checkpoint technique during training. Without using it, the RTX2080 card (8GB memory) is not able to accommodate the bert-large model. But note that, by using checkpoint, it usually takes longer time to train the model.

The trained model (that has the best performance on the dev set) will be saved to directory output/.

Test the performance of the trained models

  • To test the performance of a trained model on the MNLI and SNLI dev sets, run the command below:
python test_trained_model.py --bert_type bert-large

Performance of Trained Models


BERT-base

Accuracy: 0.8608.

Contradiction Entail Neutral
Precision 0.8791 0.8955 0.8080
Recall 0.8755 0.8658 0.8403
F1 0.8773 0.8804 0.8239

BERT-large

Accuracy: 0.8739

Contradiction Entail Neutral
Precision 0.8992 0.8988 0.8233
Recall 0.8895 0.8802 0.8508
F1 0.8944 0.8894 0.8369

ALBERT-large

Accuracy: 0.8743

Contradiction Entail Neutral
Precision 0.8907 0.8967 0.8335
Recall 0.9006 0.8812 0.8397
F1 0.8957 0.8889 0.8366

License

Apache License Version 2.0

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].