Giter Site home page Giter Site logo

frankaging / quasi-attention-absa Goto Github PK

View Code? Open in Web Editor NEW
44.0 2.0 12.0 1.2 MB

The Codebase for Quasi-Attention BERT Model for TABSA Tasks (AAAI '21)

Home Page: https://arxiv.org/abs/2010.07523

License: MIT License

Python 92.85% Shell 0.57% Jupyter Notebook 6.58%
bert sentiment-analysis aspect-based-sentiment-analysis sentihood-dataset semeval quasi-attention

quasi-attention-absa's Introduction

Quasi-Attention-ABSA

Codebase for Context-Guided BERT for Targeted Aspect-Based Sentiment Analysis (AAAI2021)

Contents

Citation

@inproceedings{wu2020context,
  title={Context-Guided BERT for Targeted Aspect-Based Sentiment Analysis},
  author={Wu, Zhengxuan and Ong, Desmond C},
  booktitle={Proceedings of the AAAI Conference on Artificial Intelligence},
  year={2021}
}

Quick start

Download Pretrained BERT Model

You will have to download pretrained BERT model in order to execute the fine-tune pipeline. We recommand to use models provided by the official release on BERT from BERT-Base (Google's pre-trained models). Note that their model is in tensorflow format. To convert tensorflow model to pytorch model, you can use the helper script to do that. For example,

cd code/
python convert_tf_checkpoint_to_pytorch.py \
--tf_checkpoint_path uncased_L-12_H-768_A-12/bert_model.ckpt \
--bert_config_file uncased_L-12_H-768_A-12/bert_config.json \
--pytorch_dump_path uncased_L-12_H-768_A-12/pytorch_model.bin

Datasets

We already preprocess the datasets for you. To be able to compare with the SOTA models, we adapt the preprocess pipeline right from this previous repo where SOTA models are trained. To regenerate the dataset, please refer to their paper and generate. Please also consider to cite their paper for this process.

Train CG-BERT Model and QACG-BERT Models

Our (T)ABSA BERT models are adapted from huggingface BERT model for text classification. If you want to take a look at the original model please search for BertForSequenceClassification. To train QACG-BERT model with semeval2014 dataset on GPU 0 and 1, you can do something like this,

cd code/
CUDA_VISIBLE_DEVICES=0,1,2,3 python run_classifier.py \
--task_name sentihood_NLI_M \
--data_dir ../datasets/sentihood/ \
--output_dir ../results/sentihood/QACGBERT-reproduce/ \
--model_type QACGBERT \
--do_lower_case \
--max_seq_length 128 \
--train_batch_size 64 \
--eval_batch_size 256 \
--learning_rate 2e-5 \
--num_train_epochs 30 \
--vocab_file ../models/BERT-Google/vocab.txt \
--bert_config_file ../models/BERT-Google/bert_config.json \
--init_checkpoint ../models/BERT-Google/pytorch_model.bin \
--seed 123 \
--evaluate_interval 25

Please take a look at code/util/args_parser.py to find our different arguments you can pass with. And you can alsp take a look at code/util/processor.py to see how we process different datasets. We currently supports almost 10 different dataset loadings. You can create your own within 1 minute for loading data. You can specify your directories info above in the command.

Analyze Attention Weights, Relevance and More

Once you have your model ready, save it to a location that you know (e.g., ../results/semeval2014/QACGBERT/checkpoint.bin). Our example code how to get relevance scores is in a jupyter notebook format, which is much easier to read. This is how you will open it,

cd code/notebook/
jupyter notebook

Inside visualization, we provide an example on how to extract attention scores, gradient sensitivity scores!

License

This repo has a Creative Commons Attribution 4.0 International License.

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.