模型简介
模型特点
模型能力
使用案例
🚀 模型ID的模型卡片
本模型卡片聚焦于一个基于Flan - T5的模型,用于情感分析和目标情感分析等任务。它通过提示调优进行了微调,能有效处理英文文本,为情感分析相关应用提供了强大支持。
🚀 快速开始
模型应用快速上手的两个步骤:
- 加载模型和分词器:
import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
# Setup model path.
model_path = "nicolay-r/flan-t5-tsa-prompt-base"
# Setup device.
device = "cuda:0"
model = T5ForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.to(device)
- 设置用于生成大语言模型响应的询问方法:
def ask(prompt):
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
inputs.to(device)
output = model.generate(**inputs, temperature=1)
return tokenizer.batch_decode(output, skip_special_tokens=True)[0]
最后,你可以按如下方式推断模型结果:
# Input sentence.
sentence = "I would support him"
# Input target.
target = "him"
# output response
flant5_response = ask(f"What's the attitude of the sentence '{context}', to the target '{target}'?")
print(f"Author opinion towards `{target}` in `{sentence}` is:\n{flant5_response}")
模型的响应如下:
Author opinion towards "him" in "I would support him despite his bad behavior." is: positive
✨ 主要特性
- 批量模式支持:自2025年2月23日起,支持批量模式,可参考 Flan - T5 provider 用于 bulk - chain 项目,测试 在此处 。
- 多用途:可用于直接应用和下游任务,如情感分析和目标情感分析。
- 提示调优:采用提示调优进行训练,提高模型性能。
📦 安装指南
文档未提及具体安装步骤,可参考模型相关仓库进行安装。
💻 使用示例
基础用法
import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
# Setup model path.
model_path = "nicolay-r/flan-t5-tsa-prompt-base"
# Setup device.
device = "cuda:0"
model = T5ForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.to(device)
def ask(prompt):
inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
inputs.to(device)
output = model.generate(**inputs, temperature=1)
return tokenizer.batch_decode(output, skip_special_tokens=True)[0]
# Input sentence.
sentence = "I would support him"
# Input target.
target = "him"
# output response
flant5_response = ask(f"What's the attitude of the sentence '{context}', to the target '{target}'?")
print(f"Author opinion towards `{target}` in `{sentence}` is:\n{flant5_response}")
高级用法
将此模型(零样本学习)以PROMPT
模式应用于RuSentNE - 2023竞赛的验证数据进行评估:
python thor_finetune.py -m "nicolay-r/flan-t5-tsa-prompt-xl" -r "prompt" \
-p "What's the attitude of the sentence '{context}', to the target '{target}'?" \
-d "rusentne2023" -z -bs 4 -f "./config/config.yaml"
可按照 Google Colab Notebook 进行实现复现。
📚 详细文档
模型详情
模型描述
- 开发者:由 nicolay - r 重构,最初实现归功于 scofield7419
- 模型类型:Flan - T5
- 语言(NLP):英语
- 许可证:Apache License 2.0
模型来源
- 仓库:Reasoning - for - Sentiment - Analysis - Framework
- 论文:https://arxiv.org/abs/2404.12342
- 演示:我们有一个 在Google - Colab上启动相关模型的代码
使用场景
直接使用
按照上述快速开始部分的步骤进行模型的加载和推理。
下游使用
请参考 Reasoning - for - Sentiment - Analysis 框架的 相关部分 。
超出适用范围的使用
此模型是Flan - T5在RuSentNE - 2023数据集上的微调版本。由于数据集呈现三尺度输出答案(positive
、negative
、neutral
),模型的行为可能会偏向于这个特定任务。
建议
用户(直接用户和下游用户)应了解模型的风险、偏差和局限性。如需进一步建议,还需要更多信息。
训练详情
训练数据
我们使用了通过GoogleTransAPI自动翻译成英语的train
数据。文本的初始来源为俄语,来自以下仓库:https://github.com/dialogue-evaluation/RuSentNE-evaluation 。英语版本的数据集可通过以下脚本自动下载:https://github.com/nicolay-r/Reasoning-for-Sentiment-Analysis-Framework/blob/main/rusentne23_download.py
训练过程
此模型使用提示微调进行训练。为完成训练过程,可使用 THoR框架的重构版本 。可使用 Google - colab笔记本 进行复现。整个训练过程进行了3个周期。
训练超参数
- 训练机制:所有配置细节在相关 配置文件 中突出显示。
评估
测试数据、因素和指标
测试数据
test
评估数据的直接链接:https://github.com/dialogue-evaluation/RuSentNE-evaluation/blob/main/final_data.csv
指标
对于模型评估,使用了两个指标:
- F1_PN -- 对
positive
和negative
类别的F1度量; - F1_PN0 -- 对
positive
、negative
和neutral
类别的F1度量;
结果
此模型的测试评估 显示 F1_PN = 60.024。以下是训练过程的日志,展示了在RuSentNE - 2023 test
集上经过4个周期后的最终性能(第5 - 6行):
F1_PN F1_PN0 default mode
0 66.678 73.838 73.838 valid
1 68.019 74.816 74.816 valid
2 67.870 74.688 74.688 valid
3 65.090 72.449 72.449 test
4 65.090 72.449 72.449 test
🔧 技术细节
此模型基于Flan - T5架构,通过提示调优在RuSentNE - 2023数据集上进行微调。训练数据经过自动翻译处理,训练过程进行了3个周期。评估使用了F1_PN和F1_PN0两个指标。
📄 许可证
本模型使用 Apache License 2.0 许可证。








