đ Sentiment Analysis T5 Model
This is an improved version of yuyijiong/T5-large-sentiment-analysis-Chinese, with more tasks added and part of the data generated by ChatGPT. It is fine-tuned on multiple Chinese and English sentiment analysis datasets.
The output format is as follows:
'Object 1 | Opinion 1 | Aspect 1 | Sentiment Polarity 1 & Object 2 | Opinion 2 | Aspect 2 | Sentiment Polarity 2 ......'
You can use the yuyijiong/quad_match_score evaluation metric for assessment.
import evaluate
module = evaluate.load("yuyijiong/quad_match_score")
predictions=["food | good | food#taste | pos"]
references=["food | good | food#taste | pos & service | bad | service#general | neg"]
result=module.compute(predictions=predictions, references=references)
print(result)
⨠Features
Supported Sentiment Analysis Tasks
["Quadruples (Target | Opinion | Aspect | Polarity)",
"Pairs (Target | Opinion)",
"Triples (Target | Opinion | Aspect)",
"Triples (Target | Opinion | Polarity)",
"Triples (Target | Aspect | Polarity)",
"Pairs (Aspect | Polarity)",
"Pairs (Opinion | Polarity)",
"Single (Polarity)"]
Additional Conditions for Answer Generation
- Answer Style Control: You can control whether the extracted opinions should be full sentences or reduced to a few words.
(Opinions should be as short as possible)
(Opinions can be longer)
(Summarize longer opinions)
Note that this condition may cause the answer to contain words different from the original text.
- Sentiment Analysis for Specified Aspects: You can perform sentiment analysis on specified aspects.
(Aspect options: Product/Logistics/Merchant/Platform)
- Handling of Null Targets: The sentiment target
target
may be null
, indicating that it is not explicitly given in the text. You can allow the model to automatically guess the null
targets.
đĻ Installation
No specific installation steps are provided in the original document, so this section is skipped.
đģ Usage Examples
Basic Usage
import torch
from transformers import T5Tokenizer, AutoModelForSeq2SeqLM
tokenizer = T5Tokenizer.from_pretrained("yuyijiong/T5-large-sentiment-analysis-Chinese-MultiTask")
model = AutoModelForSeq2SeqLM.from_pretrained("yuyijiong/T5-large-sentiment-analysis-Chinese-MultiTask", device_map="auto")
generation_config=GenerationConfig.from_pretrained("yuyijiong/T5-large-sentiment-analysis-Chinese-MultiTask")
text = 'Sentiment quadruple (target | opinion | aspect | polarity) extraction task (Opinions can be longer): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]'
input_ids = tokenizer(text,return_tensors="pt", padding=True)['input_ids'].cuda(0)
with torch.no_grad():
output = model.generate(input_ids=input_ids,generation_config=generation_config)
output_str = tokenizer.batch_decode(output, skip_special_tokens=True)
print(output_str)
Advanced Usage
Here are some usage examples:
Q: Sentiment quadruple (target | opinion | aspect | polarity) extraction task (Opinions can be longer): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Size | Large | Product#Size | Positive & Taste | Good | Product#Taste | Positive & null | Some are broken or have rotten openings deliberately sealed with mud, which is not good | Product#Freshness | Negative
Q: Sentiment quadruple (target | opinion | aspect | polarity) extraction task (Opinions can be longer, fill in null): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Size | Large | Product#Size | Positive & Taste | Good | Product#Taste | Positive & null (Some) | Have rotten openings deliberately sealed with mud, which is not good | Product#Freshness | Negative
Q: Sentiment quadruple (target | opinion | aspect | polarity) extraction task (Opinions should be as short as possible): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Size | Large | Product#Size | Positive & Taste | Good | Product#Taste | Positive
Q: Sentiment quadruple (target | opinion | aspect | polarity) extraction task (Summarize longer opinions): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Size | Large | Product#Size | Positive & Taste | Good | Product#Taste | Positive & null | Rotten openings sealed with mud | Product#Freshness | Negative
Q: Sentiment triple (target | opinion | polarity) extraction task (Opinions can be longer, fill in null): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Size | Large | Positive & Taste | Good | Positive & null (Peanuts) | Some are broken or have rotten openings deliberately sealed with mud, which is not good | Negative
Q: Determine the sentiment polarity of the following review: [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Neutral
Q: Sentiment pair (aspect | polarity) extraction task (Aspect options: Price#Cost-effectiveness/Price#Discount/Price#Level/Food#Appearance/Food#Portion/Food#Taste/Food#Recommendation): [It has a large size and good taste, but some are broken or have rotten openings deliberately sealed with mud, which is not good.]
A: Food#Portion | Positive & Food#Taste | Neutral
Q: Sentiment quadruples (target | opinion | aspect | polarity) extraction task : [The hot dogs are good , yes , but the reason to get over here is the fantastic pork croquette sandwich , perfect on its supermarket squishy bun .]
A: Hot dogs | Good | Food#Quality | Pos & Pork croquette sandwich | Fantastic | Food#Quality | Pos & Bun | Perfect | Food#Quality | Pos
đ Documentation
The model is based on the transformers
library and is designed for text2text-generation tasks. It uses the Yaxin/SemEval2016Task5NLTK
dataset and the yuyijiong/quad_match_score
metric.
Property |
Details |
Library Name |
transformers |
Pipeline Tag |
text2text-generation |
Datasets |
Yaxin/SemEval2016Task5NLTK |
Metrics |
yuyijiong/quad_match_score |
đ§ Technical Details
No technical details are provided in the original document, so this section is skipped.
đ License
No license information is provided in the original document, so this section is skipped.