快速擷取重點:新聞文章摘要
某款新聞聚合 App 需要為使用者提供篇幅較長新聞的精簡摘要,讓大家不用通讀全文也能快速掌握重點。你的任務是使用 Hugging Face 的 pipeline,從完整新聞文章產生清楚、簡潔的摘要。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
練習說明
- 使用
"cnicu/t5-small-booksum"模型建立summarizerpipeline。 - 將提供的
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)