开始使用免费开始使用

基于产品描述回答问题

一家线上零售商希望通过基于产品描述自动回答常见的产品问题来改进客服体验。您的任务是使用 Hugging Face 的 pipeline,根据客户提问从产品描述中抽取准确答案。

本练习是课程的一部分

Python 中的自然语言处理(NLP)

查看课程

练习说明

  • 使用用于问答任务的 "distilbert/distilbert-base-cased-distilled-squad" 模型创建一个 qa_pipeline
  • 使用提供的 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)
编辑并运行代码