🚀 モデルIDのモデルカード
このモデルは、ターゲット感情分析(TSA)タスクにおけるChain-of-Thought tuned verson Flan-T5を表しており、RuSentNE-2023コレクションのトレーニングデータを使用しています。このモデルは、英語で書かれたテキストを対象として設計されています。元のコレクションは非英語のテキストで構成されていたため、内容は**[googletrans]を使用して自動的に英語に翻訳**されています。
与えられた入力文とその中で言及されたエンティティ(ターゲット)に対して、このモデルは以下のクラスのいずれかを回答することで、作者の感情状態を予測します。
[positive
, negaitive
, neutral
]
モデルの詳細

2025年2月23日更新: 🔥 バッチモードサポート。
Flan-T5プロバイダを参照してください。
bulk-chainプロジェクトのためのものです。
テストはこちらで利用可能
モデルの説明
モデルのソース
🚀 クイックスタート
直接利用
この一連のスクリプトは、推論のための純粋なtorch
とtransformers
ベースのモデルの使用方法を表しています。
この例は、GoogleColab上でも利用可能です。
以下は、モデルのアプリケーションを素早く開始するための3つの手順です。
- モデルとトークナイザーの読み込み
import torch
from transformers import AutoTokenizer, T5ForConditionalGeneration
model_path = "nicolay-r/flan-t5-tsa-thor-xl"
device = "cuda:0"
model = T5ForConditionalGeneration.from_pretrained(model_path, torch_dtype=torch.bfloat16)
tokenizer = AutoTokenizer.from_pretrained(model_path)
model.to(device)
- LLMの応答を生成するための質問メソッドの設定
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]
- 思考連鎖の設定
def target_sentiment_extraction(sentence, target):
labels_list = ['neutral', 'positive', 'negative']
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 ask(step4)
最後に、以下のようにモデルの結果を推論することができます。
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."
target = "Peltier"
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に従ってください。
範囲外の利用
このモデルは、RuSentNE-2023データセットに対して微調整されたFlan-T5のバージョンを表しています。
データセットが3段階の出力回答(positive
, negative
, neutral
)を表しているため、一般的な動作はこの特定のタスクに偏っている可能性があります。
推奨事項
ユーザー(直接利用者と下流利用者の両方)は、モデルのリスク、バイアス、および制限について認識しておく必要があります。さらなる推奨事項については、より多くの情報が必要です。
📦 インストール
モデルを使用するには、上記のクイックスタートセクションの手順に従ってください。
📚 ドキュメント
トレーニングデータ
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 で提案されたThree-hop-Reasoningフレームワークを使用してトレーニングされています。
トレーニング手順の実行には、このフレームワークの再構築版が使用されています。
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エポックかかりました。

トレーニングハイパーパラメータ
- トレーニング体制: すべての構成詳細は、関連するconfigファイルに記載されています。
評価
テストデータ、要因、およびメトリクス
- F1_PN --
positive
とnegative
クラスに対するF1メジャー
- F1_PN0 --
positive
, negative
, **およびneutral
**クラスに対するF1メジャー
結果
このモデルのテスト評価では、F1_PN = 60.024が示されています。
以下は、4エポック後のRuSentNE-2023 test
セットでの最終的なパフォーマンスを示すトレーニングプロセスのログです(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
📄 ライセンス
このモデルは、Apache License 2.0の下で提供されています。