为新闻速览生成摘要
一家新闻聚合应用需要为冗长的新闻文章提供精炼摘要,方便用户无需通读全文也能快速把握要点。您的任务是使用 Hugging Face 的管道,从完整的新闻文章中生成清晰、简短的摘要。
本练习是课程的一部分
Python 中的自然语言处理(NLP)
练习说明
- 使用模型
"cnicu/t5-small-booksum"创建一个summarizer管道。 - 对给定的
article文本生成摘要。
交互式实操练习
通过完成这段示例代码来试试这个练习。
from transformers import pipeline
# Create the summarization pipeline
summarizer = pipeline(task="____", model="____")
article = """NASA's Perseverance rover has successfully collected its first rock samples from Mars, marking a significant milestone in the mission. The samples will be stored for potential return to Earth in the future, providing valuable insight into the planet's geology and potential signs of past microbial life."""
# Generate the summary
summary = ____
print(summary)