Generating natural answers with abstractive QA
Customer support chatbots aim to provide helpful, conversational answers, not just exact text snippets. To achieve this, they use abstractive question answering, which generates concise and fluent responses based on the context. Your task is to apply Hugging Face's "text2text-generation" pipeline with a model trained for abstractive QA to create natural answers from product information.
Bu egzersiz
Natural Language Processing (NLP) in Python
kursunun bir parçasıdırEgzersiz talimatları
- Create a
qa_pipelineusing the"fangyuan/hotpotqa_abstractive"model with the"text2text-generation"task. - Use the provided
contextandquestionto generate an abstractiveanswer.
Uygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
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)