模型概述
模型特點
模型能力
使用案例
🚀 模型ID的模型卡片
本模型專為英文文本設計,基於Flan - T5架構,在目標情感分析(TSA)任務上進行了微調。它能根據給定的輸入句子和其中提到的實體(目標),預測作者的情感狀態,輸出positive
、negative
或neutral
三種類別之一。
🚀 快速開始
直接使用
以下是使用該模型進行推理的三個快速步驟:
1. 加載模型和分詞器
import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
# Setup model path.
model_path = "nicolay-r/flan-t5-tsa-thor-xl"
# Setup device.
device = "cuda:0"
model = T5ForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.to(device)
2. 設置生成大語言模型響應的詢問方法
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]
3. 設置思維鏈
def target_sentiment_extraction(sentence, target):
# Setup labels.
labels_list = ['neutral', 'positive', 'negative']
# Setup Chain-of-Thought
step1 = f"Given the sentence {sentence}, which specific aspect of {target} is possibly mentioned?"
aspect = ask(step1)
step2 = f"{step1}. The mentioned aspect is about {aspect}. Based on the common sense, what is the implicit opinion towards the mentioned aspect of {target}, and why?"
opinion = ask(step2)
step3 = f"{step2}. The opinion towards the mentioned aspect of {target} is {opinion}. Based on such opinion, what is the sentiment polarity towards {target}?"
emotion_state = ask(step3)
step4 = f"{step3}. The sentiment polarity is {emotion_state}. Based on these contexts, summarize and return the sentiment polarity only, " + "such as: {}.".format(", ".join(labels_list))
# Return the final response.
return ask(step4)
最後,你可以按如下方式推斷模型結果:
# Input sentence.
sentence = "Over the past 28 years, the leader has been working hard to achieve the release of Peltier and is a member of the Leonard Peltier Defense Committee."
# Input target.
target = "Peltier"
# output response
flant5_response = target_sentiment_extraction(sentence, target)
print(f"Author opinion towards `{target}` in `{sentence}` is:\n{flant5_response}")
模型的響應如下:
Author opinion towards "Peltier" in "Over ..." is: positive
下游使用
請參考 Reasoning - for - Sentiment - Analysis 框架的相關部分。
此示例將該模型以THoR模式應用於RuSentNE - 2023競賽的驗證數據進行評估。
python thor_finetune.py -m "nicolay-r/flan-t5-tsa-thor-xl" -r "thor" -d "rusentne2023" -z -bs 4 -f "./config/config.yaml"
可參考 Google Colab Notebook 進行實現復現。
超出適用範圍的使用
該模型是Flan - T5在RuSentNE - 2023數據集上的微調版本。由於數據集的輸出答案為三分類(positive
、negative
、neutral
),模型的行為可能會偏向於該特定任務。
建議
用戶(包括直接使用和下游使用)應瞭解模型的風險、偏差和侷限性。如需進一步建議,還需要更多信息。
✨ 主要特性
- 基於Flan - T5架構,在目標情感分析任務上進行微調。
- 專為英文文本設計,輸入給定句子和目標實體,輸出作者的情感狀態。
📦 安裝指南
暫未提及具體安裝步驟,可參考代碼中的依賴庫安裝,如torch
和transformers
。
📚 詳細文檔
模型詳情
2025年2月23日更新:🔥 支持批處理模式。 請參閱 🌌 Flan - T5提供程序 以瞭解 bulk - chain 項目。 測試在此處
該模型是基於思維鏈調優版本的Flan - T5,用於目標情感分析(TSA)任務,使用了RuSentNE - 2023集合的訓練數據。
該模型專為英文文本設計。由於原始集合為非英文文本,內容已使用[googletrans]自動翻譯成英文。
對於給定的輸入句子和其中提到的實體(目標),該模型通過回答以下類別之一來預測作者的狀態:
[positive
, negative
, neutral
]
模型描述
- 開發者:由 nicolay - r 改進,初始實現歸功於 scofield7419
- 模型類型:Flan - T5
- 語言(NLP):英文
- 許可證:Apache License 2.0
模型來源
- 倉庫:Reasoning - for - Sentiment - Analysis - Framework
- 論文:https://arxiv.org/abs/2404.12342
- 演示:我們有一個在Google - Colab上運行相關模型的代碼
🔧 技術細節
訓練數據
我們使用了train
數據,這些數據已使用GoogleTransAPI自動翻譯成英文。文本的原始來源為俄語,來自以下倉庫:
https://github.com/dialogue-evaluation/RuSentNE-evaluation
英文數據集的翻譯版本可通過以下腳本自動下載: https://github.com/nicolay-r/Reasoning-for-Sentiment-Analysis-Framework/blob/main/rusentne23_download.py
訓練過程
該模型使用了三跳推理框架進行訓練,該框架在論文中提出: https://arxiv.org/abs/2305.11255
訓練過程使用了該框架的改進版本: https://github.com/nicolay-r/Reasoning-for-Sentiment-Analysis-Framework
用於復現的Google - colab筆記本: https://colab.research.google.com/github/nicolay-r/Reasoning-for-Sentiment-Analysis-Framework/blob/main/Reasoning_for_Sentiment_Analysis_Framework.ipynb
設置:Flan - T5 - xl
最大處理 64個標記,批量大小為4。
GPU:NVidia - A100,bfloat16,約30分鐘/輪次
整個訓練過程共進行了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集合的訓練數據,原始為俄語,已自動翻譯成英文。 |
許可證 | Apache License 2.0 |



