Giter Site home page Giter Site logo

declare-lab / aste-rl Goto Github PK

View Code? Open in Web Editor NEW
18.0 2.0 3.0 40 KB

This repository contains the source codes for the paper: "Aspect Sentiment Triplet Extraction using Reinforcement Learning" published at CIKM 2021.

License: Apache License 2.0

Python 100.00%
aspect-based-sentiment-analysis absa aspect-term-polarity-co-extraction aspect-term-extraction

aste-rl's Introduction

Aspect Sentiment Triplet Extraction using Reinforcement Learning (CIKM 2021)

Abstract: Aspect Sentiment Triplet Extraction (ASTE) is the task of extracting triplets of aspect terms, their associated sentiments, and the opinion terms that provide evidence for the expressed sentiments. Previous approaches to ASTE usually simultaneously extract all three components or first identify the aspect and opinion terms, then pair them up to predict their sentiment polarities. In this work, we present a novel paradigm, ASTE-RL, by regarding the aspect and opinion terms as arguments of the expressed sentiment in a hierarchical reinforcement learning (RL) framework. We first focus on sentiments expressed in a sentence, then identify the target aspect and opinion terms for that sentiment. This takes into account the mutual interactions among the triplet’s components while improving exploration and sample efficiency. Furthermore, this hierarchical RL setup enables us to deal with multiple and overlapping triplets. In our experiments, we evaluate our model on existing datasets from laptop and restaurant domains and show that it achieves state-ofthe-art performance.

πŸ”₯ πŸ”₯ πŸ”₯ Download the paper

Data

ASTE-Data-V2

ASTE-Data-V2 is originally released by the paper "Position-Aware Tagging for Aspect Sentiment Triplet Extraction". It can be downloaded here: https://github.com/xuuuluuu/SemEval-Triplet-data/tree/master/ASTE-Data-V2-EMNLP2020.

Requirements

Run

Command

python main.py {--[option1] [value1] --[option2] [value2] ... }

Change the corresponding options to set hyper-parameters:

parser.add_argument('--lr', type=float, default=0.00002, help="Learning rate")
parser.add_argument('--epochPRE', type=int, default=40, help="Number of epoch on pretraining")
parser.add_argument('--epochRL', type=int, default=15, help="Number of epoch on training with RL")
parser.add_argument('--dim', type=int, default=300, help="Dimension of hidden layer")
parser.add_argument('--statedim', type=int, default=300, help="Dimension of state")
parser.add_argument('--batchsize', type=int, default=16, help="Batch size on training")
parser.add_argument('--batchsize_test', type=int, default=64, help="Batch size on testing")
parser.add_argument('--print_per_batch', type=int, default=50, help="Print results every XXX batches")
parser.add_argument('--sampleround', type=int, default=5, help="Sample round in RL")
parser.add_argument('--numprocess', type=int, default=1, help="Number of process")
parser.add_argument('--start', type=str, default='', help="Directory to load model")
parser.add_argument('--test', type=bool, default=False, help="Set to True to inference")
parser.add_argument('--pretrain', type=bool, default=False, help="Set to True to pretrain")
parser.add_argument('--datapath', type=str, default='./data/ASTE-Data-V2-EMNLP2020/14lap/', help="Data directory")
parser.add_argument('--testfile', type=str, default='test_triplets.txt', help="Filename of test file")
parser.add_argument('--dropout', type=float, default=0.5, help="Dropout")
parser.add_argument('--seed', type=int, default=1, help="PyTorch seed value")

Start with pretraining:

python main.py --datapath ./data/ASTE-Data-V2-EMNLP2020/14lap/ --pretrain True

Then reinforcement learning fine-tuning:

python main.py --lr 0.000005 --datapath ./data/ASTE-Data-V2-EMNLP2020/14lap/ --start checkpoints/{experiment_id}/model

Inference (results will be printed, can be modified to be saved to a file in TrainProcess.py):

python main.py --datapath ./data/ASTE-Data-V2-EMNLP2020/14lap/ --start checkpoints/{experiment_id}/model --test True --testfile test_triplets.txt

Custom Data

  1. Edit Parser.py to load the necessary files.
  2. Add your data loader in DataManager.py.
  3. Modify your data loader in DataManager.py to output these information:
    • self.all_pos_tags: ['B-PRON', 'I-PRON', 'B-VERB', 'I-VERB', ...] (order depends on your dataset)
    • self.sentiments: ['POS', 'NEG', 'NEU'] (order depends on your dataset)
    • self.data: {'train': [...], 'dev': [...], 'test': [...]} (key names depend on you)
  4. Modify your data loader in DataManager.py to output self.data with these information:
    • 'sentext': "I like your dog ."
    • 'triplets': {'sentpol': 1, 'aspect': 'your dog', 'opinion': 'like', 'aspect_tags': [0,0,2,1,0], 'opinion_tags': [0,2,0,0,0]} ('sentpol' refers to sentiment polarity and 1 is the index+1 of the positive sentiment in self.sentiments, +1 is to account for the lack of sentiment having an index of 0. For aspect/opinion tags, 0 is the non-aspect/opinion span, 1 is the inside of the span and 2 is the beginning of the span.)
    • 'pos_tags': [0,2,0,6,16]
    • 'bert_to_whitespace': [[0],[1],[2],[3],[4]] (This is used for printing inference results in their original format without BERT's subword tokenisation. It shows the alignment between the BERT tokens and whitespace tokens. In this example, since BERT's tokeniser splits the tokens into the same ones as a simple whitespace tokeniser without subwords, there is a one-to-one match between the BERT and whitespace tokens.)
    • 'whitespace_tokens': ['I', 'like', 'your', 'dog', '.'] (This is used for printing inference results in their original format without BERT's subword tokenisation.)
  5. Edit main.py to use your data loader.

Acknowledgements

Our code is adapted from the code from the paper "A Hierarchical Framework for Relation Extraction with Reinforcement Learning" at https://github.com/truthless11/HRL-RE. We would like to thank the authors for their well-organised and efficient code.

Citation

Samson Yu Bai Jian, Tapas Nayak, Navonil Majumder, Soujanya Poria. 2021. Aspect Sentiment Triplet Extraction Using Reinforcement Learning. In CIKM ’21: Proceedings of the 30th ACM International Conference on Information & Knowledge Management, November 01–05, 2021, Gold Coast, Queensland, Australia. ACM, New York, NY, USA, 5 pages.

aste-rl's People

Contributors

samsonyubaijian avatar soujanyaporia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aste-rl's Issues

Using own data

Loading data...
{'NEU': 2442, 'POS': 738, 'NEG': 1390}
['NEU', 'POS', 'NEG']
#train_data: 2277
#dev_data: 587
#test_data: 777
Starting training service, overall process number: 1
Train epoch 0 ...
Process 0 start service.
Train batch 0 : F1= 0.9047619047619047 , time= 6.834511995315552
Train batch 50 : F1= 0.9473684210526316 , time= 5.462005853652954
Process Process-2:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
self._target(*self._args, **self._kwargs)
File "/content/ASTE-RL/TrainProcess.py", line 138, in worker
acc, cnt, tot, loss = workProcess(model, datas, sample_round, mode, device, sentiments, test)
File "/content/ASTE-RL/TrainProcess.py", line 25, in workProcess
preoptions, pre_aspect_actions, pre_opinion_actions, device, sentiments)
File "/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "/content/ASTE-RL/Model.py", line 156, in forward
posvs[y], bot_bert_cls, self.opinionvector(actionb), wordinbot[y],
IndexError: index 96 is out of bounds for dimension 0 with size 96

Please Help.

How much time does the example require?

Hello,

I am running your readme example locally and nothing has changes for the last 2 hours. Posting here a screenshot.

I know that time might change from machine to machine but

  • how long did it take for you to run that example?
  • do you remember you system config?

Thank you

image

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.