🚀 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 许可证。