GithubHelp home page GithubHelp logo

isakzhang / spanabsa Goto Github PK

View Code? Open in Web Editor NEW

This project forked from huminghao16/spanabsa

0.0 2.0 0.0 1.42 MB

Open-Domain Targeted Sentiment Analysis via Span-Based Extraction and Classification

License: Apache License 2.0

Python 100.00%

spanabsa's Introduction

Open-Domain Targeted Sentiment Analysis via Span-Based Extraction and Classification

This repo contains the code and data of the following paper:

Open-Domain Targeted Sentiment Analysis via Span-Based Extraction and Classification. Minghao Hu, Yuxing Peng, Zhen Huang, Dongsheng Li, Yiwei Lv. ACL 2019.

In this paper, we propose a span-based extract-then-classify framework for the open-domain targeted sentiment analysis task, which is shown as below:

This framework consists of two components:

  • Multi-target extractor
  • Polarity classifier

Both of two components utilize BERT as backbone network. The multi-target extractor aims to propose one or multiple candidate targets based on the probabilities of the start and end positions. The polarity classifier predicts the sentiment polarity using the span representation of the given target.

Requirements

Download the uncased BERT-Base model and unzip it in the current directory.

Run the following commands to set up environments:

export DATA_DIR=data/absa
export BERT_DIR=bert-base-uncased

Multi-target extractor

Train the multi-target extractor:

python -m absa.run_extract_span \
  --vocab_file $BERT_DIR/vocab.txt \
  --bert_config_file $BERT_DIR/bert_config.json \
  --init_checkpoint $BERT_DIR/pytorch_model.bin \
  --do_train \
  --do_predict \
  --data_dir $DATA_DIR \
  --train_file rest_total_train.txt \
  --predict_file rest_total_test.txt \
  --train_batch_size 32 \
  --output_dir out/extract/01

Polarity classifier

Train the polarity classifier:

python -m absa.run_cls_span \
  --vocab_file $BERT_DIR/vocab.txt \
  --bert_config_file $BERT_DIR/bert_config.json \
  --init_checkpoint $BERT_DIR/pytorch_model.bin \
  --do_train \
  --do_predict \
  --data_dir $DATA_DIR \
  --train_file rest_total_train.txt \
  --predict_file rest_total_test.txt \
  --train_batch_size 32 \
  --output_dir out/cls/01

Pipelined method

Once the above two components have been trained, we can construct a pipeline system by running the following command:

python -m absa.run_extract_span  \
  --vocab_file $BERT_DIR/vocab.txt \
  --bert_config_file $BERT_DIR/bert_config.json \
  --do_pipeline \
  --data_dir $DATA_DIR \
  --predict_file rest_total_test.txt \
  --logit_threshold 9.5 \
  --output_dir out/extract/01

python -m absa.run_cls_span \
  --vocab_file $BERT_DIR/vocab.txt \
  --bert_config_file $BERT_DIR/bert_config.json \
  --do_pipeline \
  --data_dir $DATA_DIR \
  --predict_file rest_total_test.txt \
  --output_dir out/cls/01 \
  --extraction_file out/extract/01/extraction_results.pkl

The predicted results will be saved into a file called predictions.json in the output_dir:

cat out/cls/01/predictions.json

The test performance is shown in a file called performance.txt in the output_dir:

cat out/cls/01/performance.txt

Which should produce an output like this:

pipeline, step: 210, P: 0.6991, R: 0.7156, F1: 0.7073 (common: 1638.0, retrieved: 2343.0, relevant: 2289.0)

If you train with the BERT-Large model, you should see a result similar to 74.9 F1 reported in the paper (The logit_threshold is set as 12).

Joint method

You can also try to run the joint method, which jointly train both the multi-target extractor and the polarity classifier:

python -m absa.run_joint_span \
  --vocab_file $BERT_DIR/vocab.txt \
  --bert_config_file $BERT_DIR/bert_config.json \
  --init_checkpoint $BERT_DIR/pytorch_model.bin \
  --do_train \
  --do_predict \
  --data_dir $DATA_DIR \
  --train_file rest_total_train.txt \
  --predict_file rest_total_test.txt \
  --train_batch_size 32 \
  --logit_threshold 8.0 \
  --output_dir out/joint/01

This will produce a result like this:

threshold: 8.0, step: 234, P: 0.7192, R: 0.6514, F1: 0.6836 (common: 1491.0, retrieved: 2073.0, relevant: 2289.0)

Acknowledgements

We sincerely thank Xin Li for releasing the datasets.

If you find the paper or this repository helpful in your work, please use the following citation:

@inproceedings{hu2019open,
  title={Open-Domain Targeted Sentiment Analysis via Span-Based Extraction and Classification},
  author={Hu, Minghao and Peng, Yuxing and Huang, Zhen and Li, Dongsheng and Lv, Yiwei},
  booktitle={Proceedings of ACL},
  year={2019}
}

spanabsa's People

Contributors

huminghao16 avatar

Watchers

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