说明文档
模型卡片
<!-- Provide a quick summary of what this model is/does. --> Academ 是一个针对学术讲座摘要任务微调的 BART 模型。
如需了解该模型的微调过程,您可以查看 Kaggle 上的笔记本:https://www.kaggle.com/code/yousefr/college-lectures-summarization-bart-unsupervised/
模型详情
模型描述
<!-- Provide a longer summary of what this model is. -->
这是一个已推送到 Hub 的 🤗 transformers 模型的模型卡片。该模型卡片已自动生成。
- 开发者: Yousef Gamaleldin
- 模型类型: 摘要生成
- 语言(NLP): 英语
- 许可证: MIT
- 微调自模型 [可选]: BART Large CNN
如何开始使用该模型
使用以下代码开始使用该模型。
from transformers import BartForConditionalGeneration, AutoTokenizer
model = BartForConditionalGeneration.from_pretrained('yousefg/Academ-0.5')
tokenizer = AutoTokenizer.from_pretrained('facebook/bart-large-cnn')
def get_summary(input_ids, attention_mask, context_length):
summaries = []
for i in range(0, input_ids.shape[1], context_length):
input_slice = input_ids[:, i:i + context_length] if i + context_length <= input_ids.size(1) else input_ids[:, i:]
attention_mask_slice = attention_mask[:, i:i + context_length] if i + context_length <= attention_mask.size(1) else attention_mask[:, i:]
summary = model.generate(input_slice, attention_mask = attention_mask_slice, max_new_tokens = 1654, min_new_tokens = 250, do_sample = True, renormalize_logits = True)
summaries.extend(summary[0].tolist())
summaries = tokenizer.decode(summaries, skip_special_tokens = True)
return summaries
batch = tokenizer(texts, truncation = False) # make sure to get the transcript from the lecture
input_ids = torch.tensor(batch['input_ids']).unsqueeze(0).to(device)
attention_mask = torch.tensor(batch['attention_mask']).unsqueeze(0).to(device)
summary = get_summary(input_ids, attention_mask, 1654)
print(summary)
训练详情
该模型的训练使用了自定义损失函数,以使模型达到最优长度(选择 35% 作为最优长度)。
训练超参数
- 训练精度: bf16 非混合精度<!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
- 学习率: 0.001
- 权重衰减: 0.01
- 训练轮数: 4
- 批次大小: 16
评估
<!-- This section describes the evaluation protocols and provides the results. --> 评估基于 ROUGE 1 指标,并对填充 token 进行了折扣处理。
测试数据
该模型的测试数据集包含 289 场讲座,主要来自 MIT OpenCourseWare。 <!-- This should link to a Dataset Card if possible. -->
结果
该模型在测试数据集上的 ROUGE 1 准确率达到 96%,在评估数据集上达到 93%。
总结
Academ 是一个在 2307 场讲座上训练的摘要模型,主要来自 MIT OpenCourseWare。该模型的最大序列长度为 1654,比原始模型增加了 630 个 token。
yousefg/Academ-0.5
作者 yousefg
创建时间: 2024-04-15 09:25:08+00:00
更新时间: 2024-04-20 07:37:31+00:00
在 Hugging Face 上查看