🚀 多用途文本摘要生成器(在多个摘要数据集上微调110亿参数的google/flan - t5 - xxl模型)
本项目是一个多用途的文本摘要生成模型,它基于在多个摘要数据集上微调的google/flan - t5 - xxl
模型。该模型可用于学术和日常的文本摘要任务,通过在源文档前添加不同的提示词,能灵活控制摘要的类型。
🚀 快速开始
本模型可以通过Colab进行使用,点击下面的链接在Colab中打开:
✨ 主要特性
- 多用途摘要:可用于学术和日常的文本摘要任务,适用于多种类型的文本。
- 提示词控制:通过在源文档前添加不同的提示词,可以控制摘要的类型和长度。
- 数据过滤:70%的训练数据使用
contriever
进行过滤,以余弦相似度0.6为阈值,提高数据质量。
📦 安装指南
在使用模型之前,需要安装transformers
库:
pip install transformers
💻 使用示例
基础用法
本模型需要在源文档前添加提示词以指示摘要类型,以下是一些示例提示词:
example_prompts = {
"social": "Produce a short summary of the following social media post:",
"ten": "Summarize the following article in 10 - 20 words:",
"5": "Summarize the following article in 0 - 5 words:",
"100": "Summarize the following article in about 100 words:",
"summary": "Write a ~ 100 word summary of the following text:",
"short": "Provide a short summary of the following article:",
}
提示词应以冒号结尾,输入格式示例:"Summarize the following: \n\n {input_text}"
安装transformers
库后,运行以下代码:
from transformers import pipeline
import torch
summarizer = pipeline("summarization", "jordiclive/flan-t5-11b-summarizer-filtered", torch_dtype=torch.bfloat16)
raw_document = 'You must be 18 years old to live or work in New York State...'
prompt = "Summarize the following article in 10-20 words:"
results = summarizer(
f"{prompt} \n\n {raw_document}",
num_beams=5,
min_length=5,
no_repeat_ngram_size=3,
truncation=True,
max_length=512,
)
高级用法
本模型还支持通过指定“x - y words”或“~/approximately/about/ x words”的范围来控制摘要的长度。
🔧 技术细节
训练过程
- 训练使用BF16精度,采用deepspeed stage 2并结合CPU卸载,训练1个epoch,并监控验证损失。
硬件配置
- GPU数量:8块NVIDIA A100 - SXM4 - 80GB
- CPU数量:48核
训练超参数
- 学习率(learning_rate):3e - 05
- 训练批次大小(train_batch_size):4
- 评估批次大小(eval_batch_size):4
- 随机种子(seed):42
- 分布式类型(distributed_type):多GPU
- 梯度累积步数(gradient_accumulation_steps):2
- 有效训练批次大小(effective_train_batch_size):64
- 优化器(optimizer):Adam,β1 = 0.9,β2 = 0.999,ε = 1e - 08
- 学习率调度器类型(lr_scheduler_type):线性
- 热身步数(warmup_steps):2000
- 训练轮数(num_epochs):4
框架版本
- Transformers:4.24.0
- Pytorch:1.9.1+cu111
- Deepspeed:0.7.4
- Pytorch - lightning:1.8.1
📄 许可证
本项目采用以下许可证:
- Apache - 2.0
- BSD - 3 - Clause
属性 |
详情 |
模型类型 |
基于微调的google/flan - t5 - xxl的多用途文本摘要生成器 |
训练数据 |
xsum、wikihow、cnn_dailymail/3.0.0、samsum、scitldr/AIC、billsum、TLDR、wikipedia - summary等数据集,70%的数据使用contriever过滤 |
评估指标 |
ROUGE |