🚀 T5-base针对新闻摘要任务微调模型 📖✏️🧾
本项目所有荣誉归于 Abhishek Kumar Mishra。
此模型是在 新闻摘要 数据集上对 谷歌的T5 基础模型进行微调,以完成 摘要生成 下游任务。
✨ 主要特性
T5模型详情
T5 模型由 Colin Raffel、Noam Shazeer、Adam Roberts、Katherine Lee、Sharan Narang、Michael Matena、Yanqi Zhou、Wei Li、Peter J. Liu 在论文 探索统一文本到文本转换器的迁移学习极限 中提出。以下是论文摘要:
迁移学习是一种先在数据丰富的任务上预训练模型,再在下游任务上进行微调的技术,已成为自然语言处理(NLP)领域的强大技术。迁移学习的有效性催生了多种方法、方法论和实践。在本文中,我们通过引入一个统一的框架,将每个语言问题转换为文本到文本的格式,探索了NLP迁移学习技术的格局。我们的系统研究比较了预训练目标、架构、无标签数据集、迁移方法和其他因素在数十个语言理解任务中的表现。通过将我们的探索见解与规模和新的“巨型清洁爬取语料库”相结合,我们在涵盖摘要生成、问答、文本分类等多个基准测试中取得了最先进的成果。为了促进未来NLP迁移学习的研究,我们发布了数据集、预训练模型和代码。

下游任务(摘要生成)详情 - 数据集 📚
新闻摘要
该数据集包含 4515 个示例,包含作者姓名、标题、文章链接、简短文本和完整文章。这些摘要新闻来自Inshorts,新闻文章仅从《印度教徒报》、《印度时报》和《卫报》抓取。时间范围为2017年2月至8月。
模型微调 🏋️
训练脚本是 Abhishek Kumar Mishra 创建的 此Colab笔记本 的略微修改版本,所有荣誉归于他!我还对模型进行了更多轮次(6轮)的训练。
💻 使用示例
基础用法
from transformers import AutoModelWithLMHead, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("mrm8488/t5-base-finetuned-summarize-news")
model = AutoModelWithLMHead.from_pretrained("mrm8488/t5-base-finetuned-summarize-news")
def summarize(text, max_length=150):
input_ids = tokenizer.encode(text, return_tensors="pt", add_special_tokens=True)
generated_ids = model.generate(input_ids=input_ids, num_beams=2, max_length=max_length, repetition_penalty=2.5, length_penalty=1.0, early_stopping=True)
preds = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in generated_ids]
return preds[0]
给定来自 《纽约时报》(2020年6月9日)的以下文章,标题为 乔治·弗洛伊德之死激发了一场运动。他今天将在休斯顿下葬:
在喧嚣和愤怒之后,经过数周的示威活动和对种族正义的痛苦呼吁,那个因死亡引发了一场国际运动,且最后遗言 “我无法呼吸” 成为战斗口号的人,将于周二在休斯顿的私人葬礼上安息。46岁的乔治·弗洛伊德将被安葬在他母亲墓旁的墓穴中。葬礼定于上午11点在赞美之泉教堂举行,此前在明尼阿波利斯、北卡罗来纳州和休斯顿举行了五天的公众追悼活动,而在明尼阿波利斯一名警察被录像拍到在弗洛伊德先生死亡前将膝盖压在他脖子上近九分钟之后已经过去了两周。那名警察德里克·肖文被控二级谋杀和二级过失杀人罪。他在周一的法庭出庭时保释金定为125万美元。弗洛伊德先生死后愤怒和愤慨的爆发,以及抗议活动从他死亡的城市紧张、混乱的示威迅速蔓延到从罗马到里约热内卢的国际运动,反映了多年来目睹黑人死于警察或义警之手,而变革呼声却未得到回应所积累的挫败感之深。
summarize('After the sound and the fury, weeks of demonstrations and anguished calls for racial justice, the man whose death gave rise to an international movement, and whose last words — “I can’t breathe” — have been a rallying cry, will be laid to rest on Tuesday at a private funeral in Houston.George Floyd, who was 46, will then be buried in a grave next to his mother’s.The service, scheduled to begin at 11 a.m. at the Fountain of Praise church, comes after five days of public memorials in Minneapolis, North Carolina and Houston and two weeks after a Minneapolis police officer was caught on video pressing his knee into Mr. Floyd’s neck for nearly nine minutes before Mr. Floyd died. That officer, Derek Chauvin, has been charged with second-degree murder and second-degree manslaughter. His bail was set at $1.25 million in a court appearance on Monday. The outpouring of anger and outrage after Mr. Floyd’s death — and the speed at which protests spread from tense, chaotic demonstrations in the city where he died to an international movement from Rome to Rio de Janeiro — has reflected the depth of frustration borne of years of watching black people die at the hands of the police or vigilantes while calls for change went unmet.', 80)
我们将得到:
在休斯顿的私人葬礼上。46岁的弗洛伊德死亡后将被安葬在他母亲墓旁。一名明尼苏达警察被录像拍到在他死亡前将膝盖压在他脖子上近九分钟。该警察被控二级过失杀人罪,保释金定为120万美元。
由 Manuel Romero/@mrm8488 创建 | 领英
在西班牙用心打造 ♥