🚀 多用途文本摘要生成器(在多个摘要数据集上微调的30亿参数google/flan-t5-xl模型)
本项目是一个多用途的文本摘要生成器,基于在多个摘要数据集(xsum、wikihow、cnn_dailymail/3.0.0、samsum、scitldr/AIC、billsum、TLDR)上微调的google/flan-t5-xl
模型。该模型旨在为学术和通用场景提供通用的文本摘要服务,通过在源文档前添加不同的提示词,可以控制生成摘要的类型。尽管模型训练时的最大源长度为512个标记,最大摘要长度为150个标记,但在处理大量文本时仍能取得较好的效果。
🚀 快速开始
模型使用说明
模型需要在源文档前添加提示词,以指示生成摘要的类型。提示词应以冒号结尾,例如:"Summarize the following: {input_text}"。请注意,该模型训练时使用的提示词比jordiclive/flan-t5-11b-summarizer-filtered
等模型少,因此新提示词的泛化能力可能不如这些模型。
安装依赖
在运行代码之前,请确保已经安装了transformers
库:
pip install transformers
代码示例
from transformers import pipeline
import torch
summarizer = pipeline("summarization", "jordiclive/flan-t5-3b-summarizer", torch_dtype=torch.bfloat16)
raw_document = 'You must be 18 years old to live or work in New York State...'
prompt = "Produce an article summary of the following news article:"
results = summarizer(
f"{prompt} {raw_document}",
num_beams=5,
min_length=5,
no_repeat_ngram_size=3,
truncation=True,
max_length=512,
)
提示词示例
prompts = {
"article": "Produce an article summary of the following news article:",
"one_sentence": "Given the following news article, summarize the article in one sentence:",
"conversation": "Briefly summarize in third person the following conversation:",
"scitldr": "Given the following scientific article, provide a TL;DR summary:",
"bill": "Summarize the following proposed legislation (bill):",
"outlines": "Produce an article summary including outlines of each paragraph of the following article:",
}
✨ 主要特性
- 多用途摘要:支持多种类型的文本摘要,包括新闻文章、对话、科学论文、法案等。
- 提示词控制:通过在源文档前添加不同的提示词,可以控制生成摘要的类型。
- 广泛适用性:尽管模型训练时的最大源长度为512个标记,最大摘要长度为150个标记,但在处理大量文本时仍能取得较好的效果。
🔧 技术细节
训练过程
- 训练使用BF16精度,采用DeepSpeed Stage 2进行分布式训练,共训练6个epoch,并在验证集上监控ROUGE-2指标。
硬件配置
- GPU数量:8块NVIDIA A100-SXM4-40GB GPU
- CPU数量:48核
训练超参数
- 学习率:3e-05
- 训练批次大小:5
- 评估批次大小:8
- 随机种子:42
- 分布式类型:多GPU
- 梯度累积步数:2
- 有效训练批次大小:80
- 优化器:Adam(betas=(0.9, 0.999),epsilon=1e-08)
- 学习率调度器类型:线性
- 热身步数:2000
- 训练轮数:10
框架版本
- Transformers:4.24.0
- Pytorch:1.9.1+cu111
- Deepspeed:0.7.4
- Pytorch-lightning:1.8.1
📄 许可证
本项目采用Apache 2.0和BSD 3-Clause许可证。
📚 引用信息
@misc{jordiclive_flan_t5_3b_summarizer_2023,
title={{Multi-purpose Summarizer (Fine-tuned google/flan-t5-xl on several Summarization datasets)}},
author={{Jordan Clive}},
howpublished={\url{https://huggingface.co/jordiclive/flan-t5-3b-summarizer}},
year={2023},
note={Apache 2.0 and BSD-3-Clause License. Fine-tuned on various summarization datasets including xsum, wikihow, cnn_dailymail/3.0.0, samsum, scitldr/AIC, billsum, TLDR. Designed for academic and general usage with control over summary type by varying the instruction prepended to the source document.},
url={https://huggingface.co/jordiclive/flan-t5-3b-summarizer},
}