🚀 T5 Base 模型:問答 + 摘要 + 情感分析
本模型融合了問答、文本摘要和情感檢測功能,在多個權威數據集上進行微調訓練,能為文本處理任務提供高效準確的解決方案。
🚀 快速開始
依賴項
需要 transformers>=4.0.0
✨ 主要特性
- 多任務支持:支持問答、文本摘要和情感檢測三種任務。
- 微調訓練:在 CoQa、Squad 2、GoEmotions 和 CNN/DailyMail 數據集上進行微調。
- 優秀表現:在 Squad 2 開發集上達到 F1 79.5 的分數,在 CoQa 開發集上達到 F1 70.6 的分數。
📦 安裝指南
確保安裝 transformers
庫,版本需大於等於 4.0.0:
pip install transformers>=4.0.0
💻 使用示例
基礎用法
問答任務
使用 Transformers 庫
from transformers import T5ForConditionalGeneration, T5Tokenizer
model = T5ForConditionalGeneration.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
tokenizer = T5Tokenizer.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
def get_answer(question, prev_qa, context):
input_text = [f"q: {qa[0]} a: {qa[1]}" for qa in prev_qa]
input_text.append(f"q: {question}")
input_text.append(f"c: {context}")
input_text = " ".join(input_text)
features = tokenizer([input_text], return_tensors='pt')
tokens = model.generate(input_ids=features['input_ids'],
attention_mask=features['attention_mask'], max_length=64)
return tokenizer.decode(tokens[0], skip_special_tokens=True)
print(get_answer("Why is the moon yellow?", "I'm not entirely sure why the moon is yellow."))
context = "Elon Musk left OpenAI to avoid possible future conflicts with his role as CEO of Tesla."
print(get_answer("Why not?", [("Does Elon Musk still work with OpenAI", "No")], context))
使用 Kiri 庫
from kiri.models import T5QASummaryEmotion
context = "Elon Musk left OpenAI to avoid possible future conflicts with his role as CEO of Tesla."
prev_qa = [("Does Elon Musk still work with OpenAI", "No")]
model = T5QASummaryEmotion()
model.qa("Why not?", context, prev_qa=prev_qa)
> "to avoid possible future conflicts with his role as CEO of Tesla"
文本摘要任務
使用 Transformers 庫
from transformers import T5ForConditionalGeneration, T5Tokenizer
model = T5ForConditionalGeneration.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
tokenizer = T5Tokenizer.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
def summary(context):
input_text = f"summarize: {context}"
features = tokenizer([input_text], return_tensors='pt')
tokens = model.generate(input_ids=features['input_ids'],
attention_mask=features['attention_mask'], max_length=64)
return tokenizer.decode(tokens[0], skip_special_tokens=True)
使用 Kiri 庫
from kiri.models import T5QASummaryEmotion
model = T5QASummaryEmotion()
model.summarise("Long text to summarise")
> "Short summary of long text"
情感檢測任務
使用 Transformers 庫
from transformers import T5ForConditionalGeneration, T5Tokenizer
model = T5ForConditionalGeneration.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
tokenizer = T5Tokenizer.from_pretrained("kiri-ai/t5-base-qa-summary-emotion")
def emotion(context):
input_text = f"emotion: {context}"
features = tokenizer([input_text], return_tensors='pt')
tokens = model.generate(input_ids=features['input_ids'],
attention_mask=features['attention_mask'], max_length=64)
return tokenizer.decode(tokens[0], skip_special_tokens=True)
使用 Kiri 庫
from kiri.models import T5QASummaryEmotion
model = T5QASummaryEmotion()
model.emotion("I hope this works!")
> "optimism"
📚 詳細文檔
描述
該模型在 CoQa、Squad 2、GoEmotions 和 CNN/DailyMail 數據集上進行了微調。
在 Squad 2 開發集上達到了 F1 79.5 的分數,在 CoQa 開發集上達到了 F1 70.6 的分數。
文本摘要和情感檢測功能尚未進行評估。
📄 許可證
本項目採用 Apache-2.0 許可證。
關於我們
Kiri 讓使用最先進的模型變得簡單、便捷且可擴展。
官網 | 自然語言引擎
📦 相關信息
屬性 |
詳情 |
模型類型 |
文本到文本生成 |
訓練數據 |
CoQa、Squad 2、GoEmotions、CNN/DailyMail |
評估指標 |
F1 |