使用抽象式 QA 產生自然答案
客服聊天機器人需要提供有幫助且具對話感的回答,而不只是擷取原文片段。為了達成這點,會使用抽象式問答(abstractive question answering),根據脈絡產生精簡流暢的回應。你的任務是套用 Hugging Face 的 "text2text-generation" pipeline,搭配已針對抽象式 QA 訓練的模型,從產品資訊中產生自然的答案。
本練習屬於課程
Python 的 Natural Language Processing(NLP)
練習說明
- 使用
"fangyuan/hotpotqa_abstractive"模型與"text2text-generation"任務建立qa_pipeline。 - 使用提供的
context與question產生抽象式的answer。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
from transformers import pipeline
# Create the abstractive 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?"
# Generate abstractive answer
result = qa_pipeline(f"____: {____} ____: {____}")
print(result)