🚀 T5-base を皮肉検出にファインチューニング🙄
このモデルは、GoogleのT5 base を Twitter皮肉データセット でファインチューニングし、シーケンス分類(テキスト生成として) の下流タスクに対応させたものです。
📚 T5の詳細
T5 モデルは、Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, Peter J. Liu による Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer で発表されました。以下はその概要です。
転移学習は、モデルがまずデータが豊富なタスクで事前学習され、その後下流タスクでファインチューニングされる手法で、自然言語処理(NLP)において強力な技術として浮上しています。転移学習の有効性により、アプローチ、方法論、実践の多様性が生まれています。この論文では、すべての言語問題をテキスト-to-テキスト形式に変換する統一的なフレームワークを導入することで、NLPの転移学習技術の状況を探求します。我々の体系的な研究では、数十の言語理解タスクにおいて、事前学習の目的、アーキテクチャ、ラベルなしデータセット、転移アプローチ、その他の要素を比較します。我々の探求から得られた洞察を規模と新しい「Colossal Clean Crawled Corpus」と組み合わせることで、要約、質問応答、テキスト分類などを含む多くのベンチマークで最先端の結果を達成します。NLPの転移学習に関する将来の研究を促進するために、我々はデータセット、事前学習済みモデル、コードを公開します。

📚 下流タスクの詳細(テキスト生成としてのシーケンス分類) - データセット
Twitter皮肉データセット
皮肉検出タスクのためのTwitterのトレーニングデータセットとテストデータセットは、jsonlines形式で提供されています。
各行は、以下のフィールドを持つJSONオブジェクトを含みます。
- label :
SARCASM
または NOT_SARCASM
- id: サンプルの文字列識別子。提出時にこのIDが必要になります。
- response : 皮肉な応答、つまり皮肉なツイート
- context : response の会話コンテキスト
- コンテキストは会話の順序付きリストです。つまり、コンテキストに
c1
、c2
、c3
の3つの要素がこの順序で含まれている場合、c2
は c1
への返信で、c3
は c2
への返信です。さらに、皮肉な応答が r
の場合、r
は c3
への返信です。
例えば、以下のトレーニング例の場合:
"label": "SARCASM", "response": "Did Kelly just call someone else messy? Baaaahaaahahahaha", "context": ["X is looking a First Lady should . #classact", "didn't think it was tailored enough it looked messy"]
応答ツイート "Did Kelly..." は、その直近のコンテキスト "didn't think it was tailored..." への返信で、これは "X is looking..." への返信です。あなたの目標は、コンテキスト(つまり、直近のコンテキストまたは完全なコンテキスト)も使用しながら、"response" のラベルを予測することです。
データセットサイズ統計 :
|
トレーニング |
検証 |
テスト |
Twitter |
4050 |
450 |
500 |
このデータセットは、テキスト-to-テキスト(分類を生成タスクとして)に変換するために前処理されています。
🏋️ モデルのファインチューニング
トレーニングスクリプトは、Suraj Patil によって作成された このColabノートブック の若干修正版です。すべての功績は彼に帰属します!
🧾 テストセットのメトリクス
|
適合率 |
再現率 |
F1スコア |
サポート |
derison |
0.84 |
0.80 |
0.82 |
246 |
normal |
0.82 |
0.85 |
0.83 |
254 |
|
|
|
|
|
正解率 |
|
|
0.83 |
500 |
マクロ平均 |
0.83 |
0.83 |
0.83 |
500 |
加重平均 |
0.83 |
0.83 |
0.83 |
500 |
💻 使用例
基本的な使用法
from transformers import AutoTokenizer, AutoModelWithLMHead
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-sarcasm-twitter")
model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-sarcasm-twitter")
def eval_conversation(text):
input_ids = tokenizer.encode(text + '</s>', return_tensors='pt')
output = model.generate(input_ids=input_ids, max_length=3)
dec = [tokenizer.decode(ids) for ids in output]
label = dec[0]
return label
twit1 = "Trump just suspended the visa program that allowed me to move to the US to start @USER!" +
" Unfortunately, I won’t be able to vote in a few months but if you can, please vote him out, " +
"he's destroying what made America great in so many different ways!"
twit2 = "@USER @USER @USER We have far more cases than any other country, " +
"so leaving remote workers in would be disastrous. Makes Trump sense."
twit3 = "My worry is that i wouldn’t be surprised if half the country actually agrees with this move..."
me = "Trump doing so??? It must be a mistake... XDDD"
conversation = twit1 + twit2
eval_conversation(conversation)
conversation = twit1 + twit3
eval_conversation(conversation)
conversation = twit1 + me
eval_conversation(conversation)
Created by Manuel Romero/@mrm8488 | LinkedIn
Made with ♥ in Spain