🚀 t5-small 用於標題生成
本模型是基於 t5-small 微調而來,使用 JulesBelveze/tldr_news 數據集進行標題生成任務。
🚀 快速開始
本模型可用於文本標題生成,通過微調 t5-small 模型,在特定數據集上訓練得到,能有效生成新聞等文本的標題。
✨ 主要特性
- 適用任務:支持文本摘要、標題生成、文本生成等任務。
- 訓練數據集:使用 JulesBelveze/tldr_news 數據集進行訓練。
- 評估指標:採用 ROUGE-1、ROUGE-2、ROUGE-L 和 ROUGE-Lsum 進行評估。
📦 安裝指南
文檔未提供安裝步驟,可參考 Hugging Face 官方文檔安裝相關依賴庫,如 transformers
等。
💻 使用示例
基礎用法
import re
from transformers import AutoTokenizer, T5ForConditionalGeneration
WHITESPACE_HANDLER = lambda k: re.sub('\s+', ' ', re.sub('\n+', ' ', k.strip()))
article_text = """US FCC commissioner Brendan Carr has asked Apple and Google to remove TikTok from their app stores. The video app is owned by Chinese company ByteDance. Carr claims that TikTok functions as a surveillance tool that harvests extensive amounts of personal and sensitive data from US citizens. TikTok says its data access approval process is overseen by a US-based security team and that data is only accessed on an as-needed basis under strict controls."""
model_name = "JulesBelveze/t5-small-headline-generator"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)
input_ids = tokenizer(
[WHITESPACE_HANDLER(article_text)],
return_tensors="pt",
padding="max_length",
truncation=True,
max_length=384
)["input_ids"]
output_ids = model.generate(
input_ids=input_ids,
max_length=84,
no_repeat_ngram_size=2,
num_beams=4
)[0]
summary = tokenizer.decode(
output_ids,
skip_special_tokens=True,
clean_up_tokenization_spaces=False
)
print(summary)
高級用法
文檔未提供高級用法示例,可根據實際需求調整模型參數,如 max_length
、no_repeat_ngram_size
、num_beams
等,以獲得更好的標題生成效果。
📚 詳細文檔
評估指標
屬性 |
詳情 |
評估指標 |
ROUGE-1、ROUGE-2、ROUGE-L、ROUGE-Lsum |
ROUGE-1 得分 |
44.2379 |
ROUGE-2 得分 |
17.4961 |
ROUGE-L 得分 |
41.1119 |
ROUGE-Lsum 得分 |
41.1256 |
📄 許可證
本項目採用 MIT 許可證。