The pytroch implementation of the ACL23 paper Reasoning Implicit Sentiment with Chain-of-Thought Prompting
🎉 Visit the project page: THOR-ISA
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.
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
SemEval14 Laptop (laptops) and Restaurant (restaurants), with fine-grained target-level annotations.
A. Use the Flan-T5 as the backbone LLM reasoner:
B. Evaluate with OpenAI GPT-3.5
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.
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.
- 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.
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}
}
This code is referred from following projects: CoT; Flan-T5; OpenAI-GPT3; Transformer,
The code is released under Apache License 2.0 for Noncommercial use only.