開始使用免費開始

從產品描述中回答問題

某線上零售商想要透過自動回覆基於產品描述的常見問題,來強化客服體驗。你的任務是使用 Hugging Face 的 pipeline,根據顧客的提問,從產品描述中擷取精準的答案。

本練習屬於課程

Python 的 Natural Language Processing(NLP)

檢視課程

練習說明

  • 建立一個 qa_pipeline,並使用問答專用模型 "distilbert/distilbert-base-cased-distilled-squad"
  • 使用提供的 context(產品描述)與 question 來取得答案。

動手互動練習

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

from transformers import pipeline

# Create the question-answering pipeline
qa_pipeline = pipeline(
    task="____",
    model="____"
)

context = """This smartphone features a 6.5-inch OLED display, 128GB of storage, and a 48MP camera with night mode. It supports 5G connectivity and has a battery life of up to 24 hours."""

question = "What is the size of the smartphone's display?"

# Get the answer
result = ____
print(result)
編輯並執行程式碼