開始使用免費開始

使用 pipeline 進行摘要

使用來自 Hugging Face hub 的 "cnicu/t5-small-booksum" 模型,執行一個摘要的 pipeline。

已提供一段關於艾菲爾鐵塔的 long_text,而且已經從 transformers 匯入 pipeline 模組。

本練習屬於課程

Python 的 LLM 入門

檢視課程

練習說明

  • 使用模型 "cnicu/t5-small-booksum" 載入摘要任務的模型 pipeline。
  • long_text 傳入該 pipeline 產生輸出,並將輸出限制為 50 個 tokens。
  • output 中僅存取並列印摘要文字。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

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

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

# Access and print the summarized text
print(____)
編輯並執行程式碼