🚀 BART Large CNN文本摘要模型
本模型基于Facebook的BART(双向自回归变压器)架构,具体为针对文本摘要任务进行微调的大版本。BART是Facebook AI推出的一个序列到序列模型,能够处理包括摘要在内的各种自然语言处理任务。
🚀 快速开始
📦 安装指南
你可以使用pip安装必要的库:
pip install transformers
💻 使用示例
基础用法
以下是一个简单的代码片段,展示了如何在PyTorch中使用该模型进行段落摘要任务。
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("suriya7/bart-finetuned-text-summarization")
model = AutoModelForSeq2SeqLM.from_pretrained("suriya7/bart-finetuned-text-summarization")
def generate_summary(text):
inputs = tokenizer([text], max_length=1024, return_tensors='pt', truncation=True)
summary_ids = model.generate(inputs['input_ids'], max_new_tokens=100, do_sample=False)
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
return summary
text_to_summarize = """Now, there is no doubt that one of the most important aspects of any Pixel phone is its camera.
And there might be good news for all camera lovers. Rumours have suggested that the Pixel 9 could come with a telephoto lens,
improving its photography capabilities even further. Google will likely continue to focus on using AI to enhance its camera performance,
in order to make sure that Pixel phones remain top contenders in the world of mobile photography."""
summary = generate_summary(text_to_summarize)
print(summary)
高级用法
num_train_epochs=1,
warmup_steps = 500,
per_device_train_batch_size=4,
per_device_eval_batch_size=4,
weight_decay = 0.01,
gradient_accumulation_steps=16
📚 详细文档
模型详情
属性 |
详情 |
模型类型 |
BART Large CNN |
预训练模型 |
BART Large |
微调任务 |
文本摘要 |
微调数据集 |
xsum |
📄 许可证
本模型采用MIT许可证。