抽出的QAで自然な回答を生成する
カスタマーサポートのチャットボットは、単なる引用ではなく、役に立つ会話調の回答を目指します。そのために、文脈に基づいて簡潔で流暢な応答を生成する abstractive question answering を使います。あなたのタスクは、Hugging Face の "text2text-generation" パイプラインを、abstractive QA 用に学習されたモデルと併用して、製品情報から自然な回答を作成することです。
この演習はコースの一部です
Pythonで学ぶ自然言語処理(NLP)
演習の手順
- タスク
"text2text-generation"とモデル"fangyuan/hotpotqa_abstractive"を用いて、qa_pipelineを作成します。 - 提供された
contextとquestionを使って、abstractive な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)