Skip to content

Codes for ACL 2023 paper: Reasoning Implicit Sentiment with Chain-of-Thought Prompting

License

Notifications You must be signed in to change notification settings

scofield7419/THOR-ISA

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧛🏼‍♀️⚡⚒️ THOR: Three-hop Reasoning for Implicit Sentiment

pytorch 1.8.1 pytorch 1.8.1 Build Status Build Status pytorch 1.8.1

The pytroch implementation of the ACL23 paper Reasoning Implicit Sentiment with Chain-of-Thought Prompting


🎉 Visit the project page: THOR-ISA


Quick Links


Overview

While sentiment analysis systems try to determine the sentiment polarities of given targets based on the key opinion expressions in input texts, in implicit sentiment analysis (ISA) the opinion cues come in an implicit and obscure manner.

Thus detecting implicit sentiment requires the common-sense and multi-hop reasoning ability to infer the latent intent of opinion. Inspired by the recent chain-of-thought (CoT) idea, in this work we introduce a Three-hop Reasoning (THOR) CoT framework to mimic the human-like reasoning process for ISA. We design a three-step prompting principle for THOR to step-by-step induce the implicit aspect, opinion, and finally the sentiment polarity.



Code Usage


Requirement

conda create -n thor python=3.8
# CUDA 10.2
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.3
conda install pytorch==1.10.0 torchvision==0.11.0 torchaudio==0.10.0 cudatoolkit=11.3 -c pytorch -c conda-forge
pip install -r requirements.txt

Dataset

SemEval14 Laptop (laptops) and Restaurant (restaurants), with fine-grained target-level annotations.


LLMs

A. Use the Flan-T5 as the backbone LLM reasoner:

B. Evaluate with OpenAI GPT-3.5


Training and Evaluating with Flan-T5

Use the main.py script with command-line arguments to run the Flan-T5-based THOR system.

python main.py -c <cuda_index> -r [thor|prompt] -d [restaurants|laptops] -z [True|False] -f <config_file>

Some important arguments:

  • -c, --cuda_index: Index of the GPU to use for computation (default is 0).
  • -d, --data_name: Name of the dataset. Choices are 'restaurants' or 'laptops' (default is 'laptops').
  • -r, --reasoning: Specifies the reasoning mode, with one-step prompt or multi-step thor mode (default is 'thor').
  • -z, --zero_shot: If True, the system directly performs zero-shot prediction, otherwise run the fine-tuning on the train set (default is True).
  • -f, --config: Specifies the location of config.yaml file.

Configurate more parameters in config.yaml file.


Evaluating with GPT-3.5

Go to the eval_GPT fold, and run the run_gpt_eval.py script:

python run_gpt_eval.py -k <openai_key> -d [restaurants|laptops]

Indicating your openai key. The reasoning traces and outputs of GPT for all instances are saved in output_<data_name>.txt file.


Suggestions

  • Suggest start with big enough LLM (e.g., flan-t5-xl), to better see the extraordinary reasoning ability.
  • To tune the system with supervision, preferred with bigger batch size, and with large GPU ram; suggest with A100.
  • THOR is quite slower than the prompting mode.


MISC


Citation

If you use this work, please kindly cite:

@inproceedings{FeiAcl23THOR,
  title={Reasoning Implicit Sentiment with Chain-of-Thought Prompting},
  author={Hao Fei, Bobo Li, Qian Liu, Lidong Bing, Fei Li, Tat-Seng Chua},
  booktitle = "Proceedings of the Annual Meeting of the Association for Computational Linguistics",
  pages = "1171--1182",
  year={2023}
}

Acknowledgement

This code is referred from following projects: CoT; Flan-T5; OpenAI-GPT3; Transformer,


License

The code is released under Apache License 2.0 for Noncommercial use only.

About

Codes for ACL 2023 paper: Reasoning Implicit Sentiment with Chain-of-Thought Prompting

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages