🚀 T5-large Sentiment Analysis Model
This is a sentiment analysis model based on the Transformer architecture. It can handle various sentiment analysis tasks and provides flexible output formats. It is an improved version of yuyijiong/Randeng-T5-large-sentiment-analysis-Chinese, which solves the overfitting problem. It is fine-tuned on multiple Chinese and English sentiment analysis datasets from IDEA-CCNL/Randeng-T5-784M-MultiTask-Chinese.
📦 Installation
No specific installation steps are provided in the original document, so this section is skipped.
💻 Usage Examples
Basic Usage
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)
Advanced Usage
import torch
from transformers import T5Tokenizer, AutoModelForSeq2SeqLM
tokenizer = T5Tokenizer.from_pretrained("yuyijiong/T5-large-sentiment-analysis-Chinese")
model = AutoModelForSeq2SeqLM.from_pretrained("yuyijiong/T5-large-sentiment-analysis-Chinese", device_map="auto")
generation_config=GenerationConfig.from_pretrained("yuyijiong/T5-large-sentiment-analysis-Chinese")
text = '情感四元组(对象 | 观点 | 方面 | 极性)抽取任务(观点可以较长): [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]'
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)
Usage Examples
Q:sentiment quadruples (target | opinion | aspect | polarity) extraction task (opinion can be long): [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]
A:个头 | 大 | 商品#大小 | 积极 & 口感 | 不错 | 商品#口感 | 积极 & null | 个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好 | 商品#新鲜程度 | 消极
Q:sentiment quadruples (target | opinion | aspect | polarity) extraction task (opinion can be long, complete null): [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]
A:个头 | 大 | 商品#大小 | 积极 & 口感 | 不错 | 商品#口感 | 积极 & null (个别) | 有烂掉口子刻意用泥土封着,这样做不好 | 商品#新鲜程度 | 消极
Q:sentiment quadruples (target | opinion | aspect | polarity) extraction task (opinion as short as possible): [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]
A:个头 | 大 | 商品#大小 | 积极 & 口感 | 不错 | 商品#口感 | 积极
Q:sentiment triples (target | opinion | polarity) extraction task (opinion can be long, complete null): [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]
A:个头 | 大 | 积极 & 口感 | 不错 | 积极 & null (花生) | 个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好 | 消极
Q:Judge the sentiment polarity of the following comment: [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]
A:Neutral
Q:sentiment pairs (aspect | polarity) extraction task (aspect options: price#cost-performance/price#discount/price#level/food#appearance/food#portion/food#taste/food#recommendation): [个头大、口感不错,就是个别坏了的或者有烂掉口子刻意用泥土封着,这样做不好。]
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
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 Chinese Input
- Answer Style Control: You can control the style of the extracted opinions. For example, you can specify whether the opinions should be short or long.
(Opinions as short as possible)
(Opinions can be long)
- Aspect Selection: You can specify the aspects for sentiment analysis. For example,
(Aspect options: product/logistics/merchant/platform)
- Completing Null Targets: You can allow the model to automatically guess the null targets. For example,
(Complete null)
Output Format
The output format is as follows:
'target1 | opinion1 | aspect1 | polarity1 & target2 | opinion2 | aspect2 | polarity2 ......'
Evaluation Metric
You can use the yuyijiong/quad_match_score
evaluation metric to evaluate the model's performance.
Latest Version
The latest version of the model is yuyijiong/T5-large-sentiment-analysis-Chinese-MultiTask.