🚀 多用途文本摘要生成器(在多個摘要數據集上微調的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},
}