开始使用免费开始使用

使用 pipeline 进行文本摘要

使用来自 Hugging Face hub 的 "cnicu/t5-small-booksum" 模型运行一个文本摘要的 pipeline。

已提供关于埃菲尔铁塔的 long_text,并且已导入 transformers 中的 pipeline 模块。

本练习是课程的一部分

Python 中的 LLM 入门

查看课程

练习说明

  • 使用模型 "cnicu/t5-small-booksum" 为摘要任务加载模型 pipeline。
  • long_text 传入该 pipeline 生成输出;将输出限制为 50 个 token。
  • 仅从 output 中访问并打印摘要文本。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load the model pipeline
summarizer = ____(____, ____)

# Pass the long text to the model
output = ____(____, ____)

# Access and print the summarized text
print(____)
编辑并运行代码