开始使用免费开始使用

使用抽取式 QA 生成自然回答

客户支持聊天机器人旨在提供有帮助且自然的对话式回答,而不仅仅是原文片段。为此,它们会使用抽象式问答(abstractive question answering),基于上下文生成简洁流畅的回复。您的任务是使用 Hugging Face 的 "text2text-generation" pipeline,结合经过抽象式 QA 训练的模型,从产品信息中生成自然的回答。

本练习是课程的一部分

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

查看课程

练习说明

  • 使用 "text2text-generation" 任务和 "fangyuan/hotpotqa_abstractive" 模型创建一个 qa_pipeline
  • 使用提供的 contextquestion 生成一个抽象式 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)
编辑并运行代码